#创建班级表
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(添加多对多关系)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 错误产生情景:我向一张带外键 ...

  7. 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`.` ...

  8. hibernate4一对多关联多方多写一次外键导致无法创建java.lang.NullPointerException以及Cannot add or update a child row: a foreign key constraint fails

    一篇文章里边有多张图片,典型的单向一对多关系 多方 当程序运行到这一句的时候必然报错 但是参考书也是这样写的 其中em是 EntityManager em = JPA.createEntityMana ...

  9. 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 ...

随机推荐

  1. deepin 桌面突然卡死

    deepin桌面突然卡死 使用快捷键Ctrl+alt+F2 重启systemctl

  2. py4j汉语转拼音多音字处理

    先看下效果 一 .布局 <!-- 上面的搜索框 --> <com.example.editablealphalist.widgget.ClearEditText android:id ...

  3. laravel 中with关联查询限定查询字段

    学习了下laravel5.6框架,果然很优雅,比如ActiveJieSuan model中作如下关联:(laravel模型关联关系可以查看https://laravelacademy.org/post ...

  4. hdu2121 最小树形图的虚根

    /* 最小树形图的第二题,终于有了一些理解 具体看注释 */ /* 无定根的最小树形图 建立虚root 每次只找最短的那条入边 最小树形图理解: 第一步:寻找最短弧集E:扫一遍所有的边,找到每个点权值 ...

  5. 拓展中国剩余定理(ex_crt)

    一般来讲,crt(中国剩余定理)比较常见,而ex_crt(拓展中国剩余定理)不是很常用 但是noi 2018偏偏考了这么个诡异的东西... 所以这里写一个ex_crt模板 模型: 求一个x满足上述方程 ...

  6. vue 的router的简易运用

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. spring data jpa 全面解析(实践 + 源码分析)

    前言 本文将从示例.原理.应用3个方面介绍spring data jpa. 以下分析基于spring boot 2.0 + spring 5.0.4版本源码 概述 JPA是什么? JPA (Java ...

  8. Python判断字符串是否xx开始或结尾

    判断是否xx开始 使用startswith 示例代码: String = "12345 上山打老虎" if str(String).startswith('1'): #判断Stri ...

  9. FFmpeg 常用指令集合

    不精确裁剪视频 # -ss 指定从什么时间开始 # -t 指定需要截取多长时间 # -i 指定输入文件 ffmpeg -ss 00:00:00 -t 00:00:30 -i test.mp4 -vco ...

  10. rsync注意事项

    1.sudo rsync -zavP --exclude=/.git/ --exclude=.env --exclude=web/index.php  --password-file=/usr/loc ...