在使用Django添加用户时出现报错:

1 django.db.utils.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fai
2 ls (`cms`.`app01_book_author`, CONSTRAINT `app01_book_author_book_id_df0ca405_fk_app01_book_id` FOREIG
3 N KEY (`book_id`) REFERENCES `app01_book` (`id`))')
4 [31/Mar/2019 21:20:45] "GET /addbook/ HTTP/1.1" 500 216210

解决办法,需要在setting.py文件的databases中取消外键检查:

 1 DATABASES = {
2 'default': {
3
4 'ENGINE': 'django.db.backends.mysql',
5
6 'NAME': 'cms', # 你的数据库名称
7
8 'USER': 'root', # 你的数据库用户名
9
10 'PASSWORD': '123456', # 你的数据库密码
11
12 'HOST': '', # 你的数据库主机,留空默认为localhost
13
14 'PORT': '3306', # 你的数据库端口
15 'OPTIONS': {
16 "init_command": "SET foreign_key_checks = 0;", # 取消外键检查
17 }
18 }
19 }

问题解决!!!

Cannot add or update a child row: a foreign key constraint fails的更多相关文章

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

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

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

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

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

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

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

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

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

  10. 【转】Cannot add or update a child row: a foreign key constraint fails 解决办法

    原因:设置的外键和对应的另一个表的主键值不匹配.解决方法:找出不匹配的值修改.或者清空两表数据. 转自https://blog.csdn.net/qq_29405421/article/details ...

随机推荐

  1. leaflet 用自定义pane实现图层顺序调整

    在 Leaflet 中,map panes 隐式地将图层组合在一起,而开发者并不知道这一点.这种分组允许 Web 浏览器以比单独处理图层更有效的方式同时处理多个图层. Map panes 使用 z-i ...

  2. 让AnaTraf成为您网络流量分析的最佳利器

    在快速发展的数字时代,企业对网络性能的监测与分析需求愈加旺盛.作为网络性能监测与诊断(NPMD)领域的佼佼者,AnaTraf网络流量分析仪凭借其出色的性能和易用性,正成为网络管理人员的首选工具. An ...

  3. kubernetes之包管理器Helm

    安装helm 安装helm客户端 [machangwei@mcwk8s-master ~]$ curl https://raw.githubusercontent.com/kubernetes/hel ...

  4. 【题解】P2627 [USACO11OPEN] Mowing the Lawn G

    [题解]P2627 [USACO11OPEN] Mowing the Lawn G 题目跳转 数据量比较大,暴力肯定是不行的.只能考虑用动态规划的方式来做. 这道题有许多dp设计的思路,这里提供两个: ...

  5. 【u8】二开生成的专用采购发票结算后显示结算标志但是没有生成结算单的问题

    在表体 purbillvouchs 里有个字段 upsotype 上游单据类型 不能是空,如果是代管生成的发票要填写'vmiused', 如果是普通生成的发票要填写rd,还要写上 入库单号也就是普通挂 ...

  6. Django模板templates

    1.模板文件的路径配置 2.模板中变量替换 3.变量渲染之深度查询 4.内置过滤器 过滤器的语法: {{obj|过滤器名称:过滤器参数}} 内置过滤器: 过滤器例子: 5.注释 6.多行注释 7.if ...

  7. Android 13 - Media框架(6)- NuPlayer

    关注公众号免费阅读全文,进入音视频开发技术分享群! 上一节我们通过 NuPlayerDriver 了解了 NuPlayer 的使用方式,这一节我们一起来学习 NuPlayer 的部分实现细节. ps: ...

  8. nginx37条优化

    nginx优化: 1. cpu:核心配置 方法1: worker_processes auto; 自动调用[推荐] 方法2: worker_processes 4; 手工配置 检查CPU核心:yum ...

  9. k8s网络问题以及容器跨宿主机通信原理

    [0]资源配置文件 [root@mcwk8s03 mcwtest]# ls mcwdeploy.yaml [root@mcwk8s03 mcwtest]# cat mcwdeploy.yaml api ...

  10. LeetCode 715. Range Module Range 模块 (Java)

    题目: A Range Module is a module that tracks ranges of numbers. Your task is to design and implement t ...