truncate带有外键的表出错

truncate带有外键的表出错

ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (mytest.instance, CONSTRAINT instance_ibfk_1 FOREIGN KEY (GroupID) REFERENCES mytest.mygroup (ID))

 

解决方法:

SET FOREIGN_KEY_CHECKS = 0;

TRUNCATE table1;
TRUNCATE table2;

SET FOREIGN_KEY_CHECKS = 1;
posted on 2022-04-07 10:59  ww2000e  阅读(48)  评论(0编辑  收藏  举报