0

我想将 Laravel 中的一些表列从可为空更改为具有默认值。我安装了学说/dbal,并创建了一个新的迁移,其中包含我想要更改的以下列(以前可以为空):

public function up()
    {
        Schema::table('movies', function (Blueprint $table) {
            $table->string('movieDirector')->default('')->change();
            $table->string('movieGenre')->default('')->change();
            $table->string('movieCast')->default('')->change();
        });
    }

然而,这似乎并没有做任何事情。有可能吗?谢谢!

4

1 回答 1

1

您需要使用命令创建一个新的迁移:

php artisan make:migration update_movies_table

然后,在创建的迁移类中,使用如下change方法添加这一行:

public function up()
    {
        Schema::table('movies', function (Blueprint $table) {
            $table->string('movieDirector')->default('test')->change();
            $table->string('movieGenre')->default('test')->change();
            $table->string('movieCast')->default('test')->change();
        });
    }

要进行这些更改并运行迁移,请使用以下命令:

php artisan migrate
于 2020-08-19T17:34:58.620 回答