[英]cant drop foreign key on existing table?
我正在尝试使用迁移将外键删除到现有表中,但它会引发错误,如“语法错误或访问冲突:1091 cant DROP advisor_id:check that column/key exists”。 你能帮忙吗?
首先,您必须放弃外国约束。
public function up() {
Schema::table('table_name', function (Blueprint $table) {
$table->dropForeign('table_name_consultant_id_foreign');
$table->dropColumn('consultant_id');
});
}
在删除表之前禁用外键检查,然后启用它们
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
Schema::dropIfExists('your_choice_table');
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.