在清除mysql表数据时报错:
DELETE from weshares where id >0;truncate table weshares; drop
以上方式清楚表数据的时候都报以下错误:
Error : Cannot truncate a table referenced in a foreign key constraint (`distribution`.`weshare_delivery_templates`,
CONSTRAINT `fk_weshare_delivery_templates_weshares` FOREIGN KEY (`weshare_id`) REFERENCES `distribution`.`weshares` (`id`))
原因:清空具有外键约束的表就会报错
解决方法:
SET FOREIGN_KEY_CHECKS = 0; //先归0TRUNCATE table1; //在清除数据SET FOREIGN_KEY_CHECKS = 1; //能后设置1