当清空具有外键关系表数据的时候,直接运行truncate table_name的时候,会报错
Error Code: 1701. Cannot truncate a table referenced in a foreign key constraint (
yqutesting
.table_f
, CONSTRAINTtable_f_ibfk_4
FOREIGN KEY (old_id
) REFERENCESyqutesting
.table_e
(ID
))
解决办法:
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE TABLE_E;
SET FOREIGN_KEY_CHECKS = 1;