清空具有表外键关系的数据

当清空具有外键关系表数据的时候,直接运行truncate table_name的时候,会报错

Error Code: 1701. Cannot truncate a table referenced in a foreign key constraint (yqutesting.table_f, CONSTRAINT table_f_ibfk_4 FOREIGN KEY (old_id) REFERENCES yqutesting.table_e (ID))

解决办法:

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE TABLE_E;
SET FOREIGN_KEY_CHECKS = 1;

你可能感兴趣的:(清空具有表外键关系的数据)