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; |