原文出处:https://blog.csdn.net/m0_37664906/article/details/79803503
https://blog.csdn.net/com360/article/details/7692752
禁用外码约束:
SET FOREIGN_KEY_CHECKS=0;
启动外码约束
SET FOREIGN_KEY_CHECKS=1;
查看当前FOREIGN_KEY_CHECKS的值可用如下命令
SELECT @@FOREIGN_KEY_CHECKS;
--------------------------------------------------------------------------------------------------
1217 - Cannot delete or update a parent row: a foreign key constraint fails
是由于启用了外码约束SET FOREIGN_KEY_CHECKS=1,导致无法删除或者更新数据
可以先禁用外码约束:
SET FOREIGN_KEY_CHECKS=0;
此时就可以执行增加外键语句了。修改完后再启用外码约束 SET FOREIGN_KEY_CHECKS=1即可