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

在清除mysql表数据时报错:

  1. DELETE from weshares where id >0;
  2. truncate table weshares;     
  3. 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;   //先归0
TRUNCATE table1;              //在清除数据
SET FOREIGN_KEY_CHECKS = 1;   //能后设置1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值