Solve MYSQL: Cannot delete or update a parent row: a foreign key constraint fails InnoDB when DROP table


There is conditions when we need to remove table / data in InnoDB and replaced with the new one. But the problems is, you will facing this error when DROP table that contain relational data :

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

How to solve this? It’s actually easy, open your mysql and run this command:

1
SET foreign_key_checks = 0;

This will DISABLE FOREIGN KEY CHECKS that running by INNODB when you’re try to DROP table / deleting data.
After you running that commmand, then you can start deleting data.

Make sure table / data deleted successfully by repeating your “DELETE” twice / three times.
Then, after finish, you should switch this feature back by:

1
SET foreign_key_checks = 1;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.