Monthly Archives: August 2012

ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint

As part of testing Magento’s order workflow I needed to truncate the sales tables.

However, Mysql complained with the following error:
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint

However, by switching of foreign key check, I was able to truncate the table.

SET FOREIGN_KEY_CHECKS=0;
TRUNCATE table1;
TRUNCATE table2;
SET FOREIGN_KEY_CHECKS=1;

source: http://stackoverflow.com/a/8074510

MySql dump only tables with partial name

mysqldump -u <username> <database> $(mysql -u<username> -D <database> -Bse “show tables like ‘sales%'”) > <dumpfile.sql>