mysql 外键引发的删除失败
2017-05-17 00:08
190 查看
mysql> TRUNCATE TABLE role ;
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (
mysql> TRUNCATE TABLE authority ;
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (
mysql>
mysql> TRUNCATE TABLE role ;
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (
mysql>
方案1:
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE table1;
TRUNCATE table2;
SET FOREIGN_KEY_CHECKS = 1;
方案2:
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (
test.
account, CONSTRAINT
FK_account_roleFOREIGN 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_sccf4fx8omb6jlsy2ra75xxerFOREIGN 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_roleFOREIGN 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
相关文章推荐
- MySQL创建外键失败,错误信息1005
- MySql插入删除引发的数据库死锁
- mysql外键使用错误字段名称,不能删除或修改字段名
- mysql外键级联删除
- 【原】+【转】MYSQL建立外键失败几种情况记录
- MySQL不能删除外键,抱错Error on rename of './ruler/test2child' to './ruler/#sql2-298-92' (errno: 152)
- 附:MySQL常见错误代码说明 1005:创建表失败 1006:创建数据库失败 1007:数据库已存在,创建数据库失败 1008:数据库不存在,删除数据库失败 1009:不能删除数据库文件导
- MySQL不能删除外键,抱错Error on rename of './ruler/test2child' to './ruler/#sql2-298-92' (errno: 152)
- MySQL删除外键列
- MySQL的二进制日志被全部删除导致MySQL启动失败
- 关于mysql里 主键,外键,默认 联级删除的问题
- MYSQL建立外键失败几种情况记录Can’t create table。。。。
- 玩转MySQL的外键约束之级联删除篇
- MySQL修改外键删除时操作出现error 121解决办法
- 表与表直接由于存在外键约束而导致删除操作失败
- MySQL删除外键
- mysql 外键的添加与删除
- mysql命名行下对外键的增加删除操作
- 关于mysql外键创建失败的问题
- MySQL删除外键