#创建班级表
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. Eclipse中设置Java代码格式化

    一.自定义 Java 代码格式化 [Java-Code-Formatting.xml 下载],下载完毕以后,打开 Eclipse 找到如下图界面,点击 Import 导入即可.

  2. 存储过程数据insert into select

    create or replace procedure PRO_K3_CZZH (org_name in varchar2, --财政专户名称 opertype in varchar2, --操作类型 ...

  3. Oracle12c从入门到精通(第二版) PDF 下载

    一:下载地址: 二:本书图样 三本书目录 前言 第一章 Oracle数据库概述 第二章 Oracle在Windows 8上的安装与配置 第三章 SQL基础 第四章 Oracle PL/SQL及编程 第 ...

  4. Confluence 6 管理协同编辑

    协同编辑能够让项目小组中的协同合作达到下一个高度.这个页面对相关协同编辑中的问题进行了讨论,能够提供给你所有希望了解的内容. 进入 Collaborative editing 页面来获得项目小组是如何 ...

  5. Remove Duplicates from Sorted ListII

    给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字. 示例 1: 输入: 1->2->3->3->4->4->5 输出: 1-&g ...

  6. ncnn编译安装

    1.git clone https://github.com/Tencent/ncnn 2.按照wiki说明来编译,根据需要,选择不同的编译方式.在ncnn/CMakeLists.txt中,可选择编译 ...

  7. linux之ab压力测试工具

    等待... https://www.cnblogs.com/myvic/p/7703973.html

  8. cf478d 线性dp好题

    /* 给定r个红块,g个绿块,按要求堆放 问当堆放成最大高度时,有多少种可能的堆放方式 排列要求:1.第i行放i块 2.每行同色 首先当然要确定能够放置几行 设红块有r个,绿块有g个,那么放置h行需要 ...

  9. MySQL基于ROW格式的数据恢复

    大家都知道MySQL Binlog 有三种格式,分别是Statement.Row.Mixd.Statement记录了用户执行的原始SQL,而Row则是记录了行的修改情况,在MySQL 5.6以上的版本 ...

  10. Vue2 异步获取的数据(通过ajax)获取的数据 渲染到dom上

    页面dom结构如下 <ul class="user" id="app"> <li><span>姓名: </span&g ...