如何解决如何在Laravel中将可为空的列更改为具有默认值?
我想将Laravel中的某些表列从可为空更改为具有默认值。我安装了doctrine / 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();
});
}
但是,这似乎没有做任何事情。有可能吗?谢谢!
解决方法
您需要使用以下命令创建新的迁移:
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。