我有这个迁移文件
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();
});
字符串
我想更新以在删除时级联外键,就像我已经运行了这个:
$table->foreign('table_two_id')->references('id')->on('table_two')->onDelete('cascade');
型
我该怎么做呢?是否有类似change()
的外键?
5条答案
按热度按时间efzxgjgh1#
删除外键,然后再次添加它并运行migrate。
字符串
qhhrdooz2#
Laravel docs说:
要删除外键,可以使用
dropForeign
方法。外键约束使用与索引相同的命名约定。因此,我们将连接表名和约束中的列,然后在名称后面加上“_foreign”:字符串
或者,你可以传递一个数组值,它将在删除时自动使用传统的约束名称:
型
https://laravel.com/docs/5.7/migrations#foreign-key-constraints
exdqitrt3#
您需要删除
字符串
有两个疑问。
在Laravel 8中工作
xhv8bpkk4#
1.运行
composer require doctrine/dbal
1.在迁移文件中,执行以下操作:
1.运行
php artisan migrate
r1wp621o5#
如何通过Controller
1.设置路线:
字符串
1.创建具有外键名称的控制器。
1.从Migration类扩展的Foreignkey Controller。
1.转到数据库并从表中手动删除旧主键
型