在使用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. 鸿蒙stage模型

    app.json5全局的配置文件 icon和label是应用列表的 module.json5模块配置文件 中有一个abilities其中的icon和label才是桌面的图标和名称 日志的话就是hail ...

  2. C 语言编程 — 逻辑控制语句

    目录 文章目录 目录 前文列表 结构化程序设计 条件分支语句 if/else 语句 if 语句 if/else 语句 if/else-if/else 语句 嵌套 if 语句 switch 语句 swi ...

  3. 如何启动?win11下的Linux子系统【4种方法】

    实验室的开发环境在Linux操作系统下,时不时就需要打开Linux环境去操作,而且需要本地编译或者远程SSH.这时候window和Linux切换很不方便.本科的做法就是window+虚拟机的Linux ...

  4. Supervisor 守护进程管理工具

    引言 Supervisor 是基于 Python 编程语言开发的一套通用的进程管理程序,它是通过 fork/exec 的方式把需要管理的进程作为子进程来管理. 安装 pip3 安装 superviso ...

  5. 一个简单demo展示应用接口使用goroutine优雅退出

    package main import ( "context" "errors" "log" "net/http" &q ...

  6. 将.net core api 部署成windows服务

    将.net core api 部署成windows服务   参考 https://blog.csdn.net/qq_38762313/article/details/103311944 将NSSM解压 ...

  7. nginx通过geo做访问限制

    user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; eve ...

  8. 【Azure App Service】.NET代码实验App Service应用中获取TLS/SSL 证书 (App Service Linux/Linux Container)

    在前一篇文章中,我们是把.NET 8应用读取SSL证书(X509)示例部署在App Service Windows环境中,那么如果部署在Linux环境,以及Linux Container中呢? 根据前 ...

  9. INFINI Console 与华为鲲鹏完成产品兼容互认证

    何为华为鲲鹏认证 华为鲲鹏认证是华为云围绕鲲鹏云服务(含公有云.私有云.混合云.桌面云)推出的一项合作伙伴计划,旨在为构建持续发展.合作共赢的鲲鹏生态圈,通过整合华为的技术.品牌资源,与合作伙伴共享商 ...

  10. wpfui:一个开源免费具有现代化设计趋势的WPF控件库

    wpfui介绍 wpfui是一款开源免费(MIT协议)具有现代化设计趋势的WPF界面库.wpfui为wpf的界面开发提供了流畅的体验,提供了一个简单的方法,让使用WPF编写的应用程序跟上现代设计趋势. ...