700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > mysql Error : Cannot truncate a table referenced in a foreign key constraint 清空具有外键约束的表时报

mysql Error : Cannot truncate a table referenced in a foreign key constraint 清空具有外键约束的表时报

时间:2022-03-10 06:18:10

相关推荐

mysql Error : Cannot truncate a table referenced in a foreign key constraint 清空具有外键约束的表时报

在清除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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。