Article
Ignore Foreign Key Constraints During Truncate or Drop
April 17, 2014 Updated February 19, 2017 1 min read A
If you are trying to drop/delete or empty/truncate a mysql table and you keep getting an error that you are violating a foreign key constraint, you may want to temporarily ignore that constraint. The code below demonstrates how you can tell mysql to ignore foreign key checks, delete/truncate the tables you need to, then re-enable foreign key checks
SET FOREIGN_KEY_CHECKS = 0; TRUNCATE MY_TABLE; DROP HIS_TABLE; SET FOREIGN_KEY_CHECKS = 1;