有的时候我们需要修改数据,但是因为有外键关联导致更新或删除失败,报下面的错误
annot delete or update a parent row: a foreign key constraint fails (...)
解决方案:
-- 1.关闭外键关联检查
SET foreign_key_checks = 0;
-- 2.执行更新删除操作
update....
-- 或者
delete....
-- 3.重启外键关联检查
SET foreign_key_checks = 0;