[英]Cannot find Foreign key constraint index
我的run_tasks
表具有外鍵completer_guest_id
,我需要參考其他表的列。
Schema::table('run_tasks', function (Blueprint $t) {
$t->integer('completer_id')->nullable();
$t->foreign('completer_id')->references('id')->on('users');
$t->integer('completer_guest_id')->nullable();
$t->foreign('completer_guest_id')->references('id')->on('tasks_guests');
});
但是我找不到索引: run_tasks_completer_guest_id_foreign
,因此無法刪除外鍵約束並刪除此遷移中的列:
Schema::table('run_tasks', function (Blueprint $table){
$table->dropForeign('run_tasks_completer_guest_id_foreign');
$table->dropColumn('completer_guest_id');
$table->integer('completer_guest_id')->nullable();
$table->foreign('completer_guest_id')
->references('id')
->on('guests')
->onDelete('cascade');
});
刪除表,並嘗試將創建和外鍵分配分開
Schema::dropIfExists('run_tasks');
Schema::create('run_tasks', function (Blueprint $table) {
$table->integer('completer_id')->nullable();
$table->integer('completer_guest_id')->nullable();
$table->index(['completer_id', 'completer_guest_id']);
});
Schema::table('run_tasks', function(Blueprint $table) {
$table->foreign('completer_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('completer_guest_id')->references('id')->on('guests')->onDelete('cascade');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.