Ini*_*igo 7 foreign-keys laravel-5
我有两个表具有一对一的关系,由外键约束设置。我想将onDelete规则设置为“设置默认值”,这意味着当删除外部表上的一行时,参考值将恢复为其默认值。这是我的代码:
游览表:
Schema::create('tours', function (Blueprint $table) {
$table->increments('id')->unsigned()->index();
$table->integer('grade')->unsigned()->default(1);
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
成绩表:
Schema::create('grades', function(Blueprint $table){
$table->increments('id')->unsigned()->index();
$table->string('name');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
设置外键:
Schema::table('tours', function (Blueprint $table) {
$table->foreign('grade')->references('id')->on('grades')->onDelete('set default');
});
Run Code Online (Sandbox Code Playgroud)
当我运行迁移时,它没有错误。但是,查看HeidiSQL中的表,该表无法正常工作。外键已设置,但是onDelete属性仅显示“ NO ACTION”。
随后,当我删除成绩表中的一行时,出现外键约束错误。
我究竟做错了什么?
| 归档时间: |
|
| 查看次数: |
1018 次 |
| 最近记录: |