首页 > 代码库 > ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

MySQL在删除一张表时出现

ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况。

SET FOREIGN_KEY_CHECKS = 0;

然后就可以删除表了。

删除完成后设置

SET FOREIGN_KEY_CHECKS = 1; 


drop table slow_log cascade;

ERROR 1580 (HY000) at line 1: You cannot ‘DROP‘ a log table if logging is enabled”
解决方法:执行set global slow_query_log=off,然后再次运行mysql


本文出自 “梦Dream” 博客,请务必保留此出处http://dreamy.blog.51cto.com/12471447/1897218

ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails