Mysql数据库报错:Cannot add or update a child row: a foreign key constraint fails(添加多对多关系)
#创建班级表
class Classes(models.Model):
title = models.CharField(max_length=32)
n=models.ManyToManyField('Teachers') #创建老师表
class Teachers(models.Model):
name= models.CharField(max_length=32)
age=models.IntegerField(default=30)
gender=models.BooleanField(default=False)
is_married=models.BooleanField(default=True)
address = models.CharField(max_length=50,default='xiaogan') #创建学生表
class Student(models.Model):
username=models.CharField(max_length=32)
age=models.IntegerField()
#只能写true和false
gender=models.BooleanField()
cs=models.ForeignKey(Classes,on_delete=models.DO_NOTHING)
address=models.CharField(max_length=50,default='xiaogan')
现在我想要在第三张关系表中添加数据
错误原因:老师表中没有id为4的记录。
成功添加多对多关系:
Mysql数据库报错:Cannot add or update a child row: a foreign key constraint fails(添加多对多关系)的更多相关文章
- MySql数据库插入或更新报错:Cannot add or update a child row: a foreign key constraint fails
具体报错信息: Cannot add or update a child row: a foreign key constraint fails (`xxx`.`AAA`, CONSTRAINT `t ...
- 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 ...
- 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 ...
- java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails
HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.ConstraintV ...
- 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 错误产生情景:我向一张带外键 ...
- 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`.` ...
- hibernate4一对多关联多方多写一次外键导致无法创建java.lang.NullPointerException以及Cannot add or update a child row: a foreign key constraint fails
一篇文章里边有多张图片,典型的单向一对多关系 多方 当程序运行到这一句的时候必然报错 但是参考书也是这样写的 其中em是 EntityManager em = JPA.createEntityMana ...
- admin添加用户时报错:(1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_l
在stackoverflow找到答案: DATABASES = { 'default': { ... 'OPTIONS': { "init_command": "SET ...
随机推荐
- 《MySQL5.7从入门到精通(视频教学版)》
· 一:书籍PDF获取途径 pdf 文档 在 此QQ群(668345923) 的群文件里面 学习视频资源 二:书籍介绍 本书主要包括MySQL的安装与配置.数据库的创建.数据表的创建.数据类型和运算符 ...
- Confluence 6 通过 SSL 或 HTTPS 运行 - 创建或请求一个 SSL 证书
在启用 HTTPS 之前,你需要一个有效的证书,如果你已经有了一个有效的证书,你可以直接跳过这个步骤,进入 step 2. 你可以创建一个自签名的证书,或者从信任的 Certificate Autho ...
- Confluence 6 如何备份存储文件和页面信息
备份的 ZIP 文件包含有 entities.xml,这个 XML 文件包含有 Confluence 的所有页面内容和存储附件的目录. 备份 Zip 文件结构 页面的附件是存储在附件存储目录中的,通过 ...
- nginx官方模块之http_sub_module
作用 http内容替换 语法 示例 html代码与结果如下:
- yum安装软件内容
linux yum源改为阿里yum源 1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.back ...
- UEFI rootkit 工具LoJax可以感染电脑主板(mainboard)
1.UEFI(Unified Extensible Firmware Interface)统一扩展接口,UEFI rootkit是以在UEFI中植入rootkit ,18年9月份ESET首次公开了境外 ...
- Winhex数据恢复笔记(五)
一.上次介绍了Windows API函数,这次对Windows API函数的参数做个笔记 1.IpFileName: 文件名指针,也可指向 MS-Dos设备名,同时支持文件和设备名,函数分为两个版本 ...
- js 压缩上传的图片方法(默认上传的是file文件)
//压缩图片方法 function compressImg(file,callback){ var src; var fileSize = parseFloat(parseInt(file['size ...
- python之ORM操作
1. SQLalchemy简介 SQLAlchemy是一个开源的SQL工具包,基本Python编程语言的MIT许可证而发布的对象关系映射器.SQLAlchemy提供了“一个熟知的企业级全套持久性模式, ...
- nginx 监控脚本
[root@Client_Download_Source shell]# cat start.nginx.sh #!/bin/bash while true do sleep 2 check=`net ...