Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5-在创建表时将字段设置为可为空_Php_Laravel_Laravel 5.8 - Fatal编程技术网

Php Laravel 5-在创建表时将字段设置为可为空

Php Laravel 5-在创建表时将字段设置为可为空,php,laravel,laravel-5.8,Php,Laravel,Laravel 5.8,我有一个多租户安装,并且正在自动创建新主机。我试图在第一次创建表时为每个列在表上设置Allow Null值。这不起作用,但在以后的迁移文件中将向现有表中添加新列以将其设置为可空 我使用以下方法首先创建表,不设置null: public function up() { Schema::create('phone_logs', function (Blueprint $table) { $table->bigIncrements('id'); $tabl

我有一个多租户安装,并且正在自动创建新主机。我试图在第一次创建表时为每个列在表上设置Allow Null值。这不起作用,但在以后的迁移文件中将向现有表中添加新列以将其设置为可空

我使用以下方法首先创建表,不设置null:

public function up()
{
    Schema::create('phone_logs', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('type')->nullable(true)->change();
        $table->string('groupId')->nullable(true)->change();
        $table->string('status')->nullable(true)->change();
        $table->string('status_code')->nullable(true)->change();
        $table->longText('message')->nullable(true)->change();
        $table->string('sender')->nullable(true)->change();
        $table->string('receiver')->nullable(true)->change();
        $table->string('contactNumber')->nullable(true)->change();
        $table->dateTime('date')->nullable(true)->change();
        $table->string('messageUID')->nullable(true)->change();
        $table->integer('has_read')->nullable(true)->change();
        $table->string('lists_sent')->nullable(true)->change();
        $table->string('user_id')->nullable(true)->change();
        $table->string('audio')->nullable(true)->change();
        $table->timestamps();
    });
}
然后使用此选项将3个新列添加到表中,并将其设置为null:

public function up()
{
    Schema::table('phone_logs', function (Blueprint $table) {
        //
        $table->string('reply_numbers')->nullable(true);
        $table->text('auto_response_1')->nullable(true);
        $table->dateTime('schedule_date')->nullable(true);
    });
}

在阅读了一些建议后,我添加了->change(),并且还包括了nullable(true),而不是建议中的nullable(),但仍然没有设置,需要我手动设置。

您是在创建新表还是在更改现有表?创建,schema::create。Schema::table稍后要使用不同的迁移文件添加更多的列,请设置可为null的fineable。如果要创建新表,不需要使用
->change()
,因为没有什么可以更改的:)您只需执行
$table->string('name')->nullable()你可以走了。或者至少你应该能够做到这一点。这就是我使用的,我只是在阅读了一些关于5后更改的其他建议后才添加了->change()。不管有没有它,我都看不到有什么变化,仍然允许Null被取消选中。我也尝试过使用->default('NULL'),但也不起作用。您是否已经运行了此迁移?如果是这样,您必须重新运行迁移(通过回滚或刷新等),然后再次运行,或者在新迁移中执行此操作。我有很多迁移都具有
NULL()
,然后在运行时,通过
描述示例检查时生成
NULL:YES
是否正在创建新表或更改现有表?正在创建,模式::创建。Schema::table稍后要使用不同的迁移文件添加更多的列,请设置可为null的fineable。如果要创建新表,不需要使用
->change()
,因为没有什么可以更改的:)您只需执行
$table->string('name')->nullable()你可以走了。或者至少你应该能够做到这一点。这就是我使用的,我只是在阅读了一些关于5后更改的其他建议后才添加了->change()。不管有没有它,我都看不到有什么变化,仍然允许Null被取消选中。我也尝试过使用->default('NULL'),但也不起作用。您是否已经运行了此迁移?如果是这样,您必须重新运行迁移(通过回滚或刷新等),然后再次运行,或者在新迁移中执行此操作。我有很多迁移都具有
NULL()
,然后在运行时,通过
描述示例检查时生成
NULL:YES
在SQL中。