在做hibernate的manytoone的时候,在删除表的时候出现:
Cannot delete or update a parent row: a foreign key constraint fails
在Mysql中创建表的时候,设置了表的自我关联(就是一个表有个主键,还有另外一个字段,该字段作为本表的外键,关联这个主键),插入一条数据 后,如果想删除这条数据,首先必须删除外键约束,drop constrain 外键名称 ,但是会发现,删除外键约束后,在mysql的命令行中使用show create table 表名,查看表的结构,你会发现,其实还有个key 外键名,这个东东;这个东东相当于索引index,所以删除的时候,使用语句alter table drop index 外键名称,然后使用show create table 表名,去查看,发现,key 也删除了,这个时候,你要是再使用drop table 表名,会提示你如下错误:
Cannot delete or update a parent row: a foreign key constraint fails
解决方法:
SET FOREIGN_KEY_CHECKS = 0;
这样就可以解决了,使用drop table 表名,就可以删除表了!
删除完成之后再设置回来:SET FOREIGN_KEY_CHECKS = 1;
相关推荐
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails 这是因为你尝试删除的表中的字段被用作了其他表的外键,因此在删除这个表(父表)之前必须先删除具有外键的表(子表)...
在SSM项目中执行一个删除用户操作时报错,遂在navicat中尝试是否可以直接删除,报如下所示错误 student表的主键是selectedcourse表的外键,当需要删除student表内的一行数据时,必须在selectedcourse表内设置该外键...
(1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_fk_auth_user_id` FOREIGN KEY (`user_id`) ...
这篇文章主要涉及到在数据创建表时,遇到ERROR 1215 (HY000): Cannot add foreign key constraint 问题方面的内容,对于在数据创建表时,遇到同样问题感兴趣的同学可以参考一下。 一、问题的提出 创建两个表: ...
Cannot delete or update a parent row: a foreign key constraint fails (...) 这可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况。 SET ...
aforeignkeyconstraintfails (...) 这是因为MySQL中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况。 禁用外键约束,我们可以使用: SETFOREIGN_KEY_CHECKS=...
阅读此书以了解根本原因:SQL FOREIGN KEY Constraint [^]
The foreign key in a table T1 _____ the same _____ as the corresponding primary key in table T2. must have, name need not have, name must have, domain (a) I, II, and III (b) I and II (c) ...
在MySQL中,InnoDB引擎类型的表支持了外键约束。外键的使用条件:1.两个表必须是InnoDB表,MyISAM表暂时不支持外键(据说以后的版本有可能支持,但...外键的定义语法: 代码如下:[CONSTRAINT symbol] FOREIGN KEY [i
constraint 外键名 foreign key(字段) references 主表(字段) on delete 级联动作 on update 级联动作 3、级联动作 1、cascade :删除、更新同步(被参考字段) 2、restrict :不让主表更新、删除 3、set null...
Grammatical theory From transformational grammar to constraint-based approaches Stefan Müller 2017新书,欢迎对形式语言学,自然语言处理等领域感兴趣读者下载。
Processing Rule : Short-Circuit Constraint (Allowed=Not Allowed) (On the board ),(On the board ) Rule Violations :0 Processing Rule : Broken-Net Constraint ( (On the board ) ) Rule Violations :0 ...
"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'a3b6420a-6724-11ea-b2a3-d773d1d6999f' for key 'callId'\nThe SQL being executed was: INSERT INTO `ly_call` (`call_id`, `mobile`, ...
课程设计—仓库设备管理系统.doc 创建基本表的SQL代码: create table Equipment ( ...alter table Stock add constraint Eno3 foreign key(Eno) references Equipment(Eno) on update cascade on delete cascade
foreign key(AID) references dbo.A(AID) on delete cascade on update cascade go alter table dbo.C add constraint FK_C_B_BID foreign key(BID) references dbo.B(BID) on delete cascade on update cascade go ...
SQL Server 2000中的列级约束与表级约束 在SQL Server 2000中有5 种约束: 主键约束(primary key constraint) 唯一性约束(unique constraint) 检查约束(check constraint...外部键约束(foreign key constraint)
利用Python+Gurobi编写代码,复现文章:Solving two-stage robust optimization problems using a column-and- constraint generation method。
Coarse grained Hostility Detection: The task is to predict whether a given post is hostile or not. ii. Fine-grained Hostility Detection: The task is to detect one or more hostile dimensi
This two-volume book shows how to design and implement web applications with a model-based engineering approach, using the two most relevant technology plat- forms for web development: JavaScript and ...