dmartinezla
3/31/2014 - 9:33 AM

Truncate table with foreign keys

Truncate table with foreign keys

If trying to truncate MySQL InnoDB tables and you are getting an error because of foreign keys constraints try disabling the foreign keys checks.

SET FOREIGN_KEY_CHECKS = 0;
..
TRUNCATE tableName;
TRUNCATE tableName2;
..
SET FOREIGN_KEY_CHECKS = 1;