乐者为王

Do one thing, and do it well.

Cannot delete or update a parent row: a foreign key constraint fails

在SQLyog中Import Data或Empty Table时,出现:

1
2
Error No. 1451
Cannot delete or update a parent row: a foreign key constraint fails

查看官方文档Setting FOREIGN_KEY_CHECKS to 0 can also be useful for ignoring foreign key constraints during LOAD DATA and ALTER TABLE operations.知道这可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况。

1
SET FOREIGN_KEY_CHECKS = 0;

Comments