CyberKeeda In Social Media

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




Reason - It’s because we have tried to update a table without a WHERE that uses a KEY column.

Fix - The quickest fix is to simply add SET SQL_SAFE_UPDATES=0; before your query 
or execute the query before your truncate query


Use the below mentioned commands within your db to fix it.

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE table1;
TRUNCATE table2;
Once records has been removed , revert the changes.
SET FOREIGN_KEY_CHECKS = 1;

No comments:

Post a Comment

Designed By Jackuna