Force DROP TABLE in MySQL with foreign key constraint

When trying to update a local copy of one of my MySQL databases, I got the error
Cannot delete or update a parent row: a foreign key constraint fails
when issuing the command

DROP TABLE IF EXISTS `table_a`;

As I immediately recreate the tables with the necessary foreign key constraints, I wanted to temporarily remove the constraints. After some Googl’ing, I learned that it is as simple as

SET foreign_key_checks = 0;
DROP TABLE IF EXISTS `table_a`;
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.