我有这个迁移文件
Schema::create('table_one', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->integer('table_two_id')->unsigned();
$table->foreign('table_two_id')->references('id')->on('table_two');
$table->timestamps();
});
我想更新以使其成为->onDelete('cascade');
$table->foreign('table_two_id')->references('id')->on('table_two')->onDelete('cascade');
执行此操作的最佳方法是什么?
有没有像->change();
这样的东西谢谢
最佳答案
删除外键然后再次添加并运行迁移。
public function up()
{
Schema::table('table_one', function (Blueprint $table) {
$table->dropForeign(['table_two_id']);
$table->foreign('table_two_id')
->references('id')
->on('table_two')
->onDelete('cascade');
});
}
关于php - Laravel::更新外键的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38427672/