Cannot add or update a child row: a foreign key constraint fails
在使用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的更多相关文章
- 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 ...
- 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`.` ...
- 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 ...
- 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 ...
- 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 ...
- 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 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 错误产生情景:我向一张带外键 ...
- hibernate4一对多关联多方多写一次外键导致无法创建java.lang.NullPointerException以及Cannot add or update a child row: a foreign key constraint fails
一篇文章里边有多张图片,典型的单向一对多关系 多方 当程序运行到这一句的时候必然报错 但是参考书也是这样写的 其中em是 EntityManager em = JPA.createEntityMana ...
- 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 ...
- 【转】Cannot add or update a child row: a foreign key constraint fails 解决办法
原因:设置的外键和对应的另一个表的主键值不匹配.解决方法:找出不匹配的值修改.或者清空两表数据. 转自https://blog.csdn.net/qq_29405421/article/details ...
随机推荐
- 智慧城市three.js数字孪生三维展示城市建筑轮廓数据获取方法分析和AI算法方案剖析
一.目前世面上有的2种免费方案是 1.OpenStreetMap开源网站下载, 2.blender的gis插件获取城市建筑轮廓. 缺点是:只有重点城市和省会城市,一些地级市或者县级市基本没有数据. 二 ...
- JDK源码阅读-------自学笔记(十五)(java.lang.Math数学类)
Math类简介 用于常见的数学方法 如果需要更加强大的数学运算能力,计算高等数学中的相关内容,可以使用apache commons下面的Math类库 常用方法及实战 abs 绝对值 实例: 1 //绝 ...
- 4G EPS 中的小区搜索
目录 文章目录 目录 前文列表 小区搜索(Cell Search)流程 PSS(主同步信号)与 SSS(辅同步信号) DL-RS(下行参考信号) PBCH(物理广播信道) PDSCH(物理下行共享信道 ...
- springboot使controller异步调用
调用controller方法,遇到操作时间很长的情况下,不希望前端一直等待操作,而希望前端立马接收到操作启动的反馈,而真正的操作在后端执行,需要用到异步调用的方法.实现步骤如下: 一.配置异步支持: ...
- containerd 源码分析:启动注册流程
0. 前言 containerd 是一个行业标准的容器运行时,其强调简单性.健壮性和可移植性.本文将从 containerd 的代码结构入手,查看 containerd 的启动注册流程. 1. 启动注 ...
- 原生Django出现同源策略跨域的解决方式
解决方式: 在返回数据的时候,添加响应头信息: 例如:
- opencv-python 实现鱼眼矫正 棋盘矫正法
.htmledit_views address, .htmledit_views cite, .htmledit_views dfn, .htmledit_views em, .htmledit_vi ...
- 7.13早考试总结(NOIP模拟13)[工业题·卡常题·玄学题]
人的记忆本来就是暧昧的,不值得信任. 前言 又是令人头疼的数学部分..还是太菜了.. 晚上还有一场,当场裂开. T1 工业题 解题思路 首先,这个题的暴力还是非常好像的,直接按照题目要求码就好了. 对 ...
- (C#) IIS 响应标头过滤敏感信息(如:Server/X-Powered-By等) 运维知识
背景: 再一次净网行动中,客户要求安全改造发现了接口请求的header标头中出现如图中的敏感信息. 说明: 其意义在于告知浏网站是用什么语言或者框架编写的.解决办法就是修改该响应头为一个错误的值,将攻 ...
- 给 ES 插上向量检索的翅膀 | DataFunSummit 2023 峰会演讲内容速达
近日,由 DataFun 主办的 DataFunSummit 2023 数据基础架构峰会 圆满落下帷幕,本次峰会邀请了腾讯.百度.字节.极限科技.Zilliz 等众多企业技术专家为大家带来分布式存储以 ...