10年 Java程序员,硬核人生!勇往直前,永不退缩!

欢迎围观我的git:https://github.com/R1310328554/spring_security_learn 寻找志同道合的有志于研究技术的朋友,关注本人微信公众号: 觉醒的码农,或Q群 165874185

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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  阅读(487)  评论(0编辑  收藏  举报