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 ...
随机推荐
- vs2015常用代码块与自定义代码块
常用代码块 代码段名 描 述 #if 该代码段用#if和#endif命令围绕代码 #region 该代码段用#region和#endregion命令围绕代码 ~ 该代码段插入一个析构函数 att ...
- HDU - 6333 Harvest of Apples
题意: T次询问,每次给出n,m.求sigma(k:0->m)C(n, k). 题解: 用离线莫队来做. 令S(n,m) = sigma(k:0->m)C(n, k). S(n+1, m) ...
- BZOJ1597 & 洛谷2900:[USACO2008 MAR]Land Acquisition 土地购买——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1597 https://www.luogu.org/problemnew/show/P2900 约翰准 ...
- 学习操作Mac OS 之 使用brew安装软件
安装brew软件 安装方法: 在Mac中打开Termal: 输入命令: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercont ...
- Linux之异步通知20160702
异步通知,主要说的是使用信号的方式,同时使用信号也是实现进程之间通信的一种方式. 多的不说,我们直接看代码: 首先应用程序的: #include <sys/types.h> #includ ...
- IE的CSS渲染跟其它浏览器有什么不同
由于IE系浏览器对标准的支持不够好,导致Web开发中经常需要去处理浏览器兼容性问题,特别有些莫名其妙的问题很让人头疼,今天要说这个问题就是这样的,先从插入CSS的三种方法说起: 外部样式(Extern ...
- shell运用
在shell脚本一 中,我讨论了shell脚本的语法规范,shell脚本的变量,以及shell脚本的测试语句. 仅仅懂得这些只能写简单的脚本,在简单的脚本中各条语句按顺序执行,从而实现自动化的管理,顺 ...
- spring 整合 redis 单机版
增加spring配置文件: application-jedis.xml <?xml version="1.0" encoding="UTF-8"?> ...
- CentOS 6.5 下 QT4 连接 mysql 数据库的步骤
QT4 的安装请参考: CentOS 6.5 下安装 QT 4 mysql 的安装请参考: CentOS 6.5 下安装配置 mysql 1. 预防万一,先安装一下mysql-devel(一定要装!) ...
- 微服务与devops的文章推荐
http://www.sohu.com/a/125040520_355140 http://www.csdn.net/article/2015-11-18/2826253 http://www.cnb ...