foreign key constraint fails错误的原因
建表:
CREATE TABLE Course
( Cno Char(4) PRIMARY KEY,
Cname Char(40),
Cpno Char(4),
Ccredit Int,
FOREIGN KEY (Cpno) REFERENCES Course(Cno)
);
插入数据:
INSERT INTO Course VALUES('1','数据库','5',4);
INSERT INTO Course VALUES('2', ' 数学', '',2);
INSERT INTO Course VALUES('3', 信息系统', '1',4);
INSERT INTO Course VALUES('4', ' 操作系统', '6',3);
INSERT INTO Course VALUES('5', ' 数据结构', '7',4);
INSERT INTO Course VALUES('6', '数据处理', '',2);
INSERT INTO Course VALUES('7', ' PASCAL语言', '6',4);
报错:
cannot add or update a child row....
原因:
外键限制,无法插入,在上面的例子中就是第一个插入INSERT INTO Course VALUES('1','数据库','5',4);时先导课程5没有这个选项,因此会报错,需要调整导入的顺序就可以了,即没有先导的课程先插入,然后插入有先导并且先导课程已经插入了的。
感悟:
初学数据库,而且全自学,还很需要学习!
foreign key constraint fails错误的原因的更多相关文章
- Error Code: 1452 Cannot add or update a child row: a foreign key constraint fails
错误: Error Code: 1452 Cannot add or update a child row: a foreign key constraint fails 错误产生情景:我向一张带外键 ...
- MySQL主从复制中断,报“Error on master: message (format)='Cannot delete or update a parent row: a foreign key constraint fails' error code=1217” 错误
前几天,发现从库挂了,具体报错信息如下: 分析思路 1. 因为我采用的是选择性复制,只针对以下几个库进行复制: card,upay,deal,monitor,collect.所以,不太可能出现对于sa ...
- insert时报Cannot add or update a child row: a foreign key constraint fails (`yanchangzichan`.`productstatusrecord`, CONSTRAINT `p_cu` FOREIGN KEY (`cid`) REFERENCES `customer` (`cid`))错误
mybatis在insert时报Cannot add or update a child row: a foreign key constraint fails (`yanchangzichan`.` ...
- MySQL设置外键报错 #1452 - Cannot add or update a child row: a foreign key constraint fails 解决方法
MySQL数据库,当我尝试在A表中设置B表的主键为外键时,报出错误:#1452 - Cannot add or update a child row: a foreign key constraint ...
- 【转】 #1451 - Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法
转载地址:http://blog.csdn.net/donglynn/article/details/17056099 错误 SQL 查询: DELETE FROM `zmax_lang` WHERE ...
- Hibernate级联删除时:Cannot delete or update a parent row: a foreign key constraint fails异常
在删除主表数据时,报了一个异常 Cannot delete or update a parent row: a foreign key constraint fails 原因是主表中还包含字表的数据, ...
- Error 'Cannot add or update a child row: a foreign key constraint fails故障解决
一大早的,某从库突然报出故障:SQL线程中断! 查看从库状态: mysql> show slave status\G Slave_IO_State: Waiting for master to ...
- IntegrityError at /admin/users/userprofile/add/ (1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_
报错现象 在执行 django 后台管理的时候添加数据导致 1452 错误 报错代码 IntegrityError at /admin/users/userprofile/add/ (1452, 'C ...
- ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails ()
centos7.5 删除表空间文件失败 问题: mysql> alter table country discard tablespace; ERROR 1451 (23000): Cannot ...
随机推荐
- bpf移植到3.10
bpf_common.h中显示的是/usr/src/linux-headersXXXX/include/uapi/linux 竟然会识别系统的挂载选项:
- Android studio出现Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"的解决办法
最近更新了一下Android Studio(下文简写成AS),然后打开工程发现出现Error:Unable to tunnel through proxy. Proxy returns "H ...
- IO复用、多进程和多线程三种并发编程模型
I/O复用模型 I/O复用原理:让应用程序可以同时对多个I/O端口进行监控以判断其上的操作是否可以进行,达到时间复用的目的.在书上看到一个例子来解释I/O的原理,我觉得很形象,如果用监控来自10根不同 ...
- 从一个ListBox中的元素点击导入另一个ListBox元素中
先看效果图:
- codeforces 981 C.Useful Decomposition
C. Useful Decomposition time limit per test 1 second memory limit per test 256 megabytes input stand ...
- java 中使用Base64
byte[] cipherData = Base64.encodeBase64(plainText.getBytes()); //默认不换行 byte[] cipherData = Base64.en ...
- BZOJ3781:小B的询问——题解
https://www.luogu.org/problemnew/show/2709 http://www.lydsy.com/JudgeOnline/problem.php?id=3781 题目描述 ...
- BZOJ4105 [Thu Summer Camp 2015]平方运算 【线段树】
题目链接 BZOJ4105 题解 平方操作orz,虽说应该是线段树,但是不会维护啊QAQ 小瞧一眼题解... 平方成环?环长\(lcm\)小于\(60\)? 果然还是打表找规律题.... 那就很好做了 ...
- Navcat中Oracle连接的坑-Instant Client
报错信息: 官方下载Instant Client下载: http://www.oracle.com/technetwork/cn/topics/intel-macsoft-102027-zhs.htm ...
- Tomcat启动web项目报Bad version number in .class file (unable to load class ...)错误的解决方法
一.发现问题:启动 tomcat 控制台报该错误. 二.原因:tomcat 的 jdk 版本和编译.class的 jdk 版本不一致. 三.解决办法: 步骤一: 查看 MyEclipse ...