mysql 外键引发的删除失败

mysql> TRUNCATE TABLE role ;
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (test.account, CONSTRAINT FK_account_role FOREIGN KEY (roleId) REFERENCES test.role (id))
mysql> TRUNCATE TABLE authority ;
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (test.role_authority, CONSTRAINT FK_sccf4fx8omb6jlsy2ra75xxer FOREIGN KEY (authorityId) REFERENCES test.authority (id))
mysql>
mysql> TRUNCATE TABLE role ;
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (test.account, CONSTRAINT FK_account_role FOREIGN KEY (roleId) REFERENCES test.role (id))
mysql>

方案1:

SET FOREIGN_KEY_CHECKS = 0;

TRUNCATE table1;
TRUNCATE table2;

SET FOREIGN_KEY_CHECKS = 1;

方案2:

Option 1: which does not risk damage to data integrity:

    Remove constraints
    Perform TRUNCATE
    Delete manually the rows that now have references to nowhere
    Create constraints
posted on 2017-05-17 00:08 CanntBelieve 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/FlyAway2013/p/6864466.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值