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 ...
随机推荐
- 从零开始写 Docker(十四)---重构:实现容器间 rootfs 隔离
本文为从零开始写 Docker 系列第十四篇,实现容器间的 rootfs 隔离,使得多个容器间互不影响. 完整代码见:https://github.com/lixd/mydocker 欢迎 Star ...
- 基于AIRIOT平台构建低成本、更聪明的智能环卫系统,让管理更加高效智能
环卫工程作为城市基础设施保障,是城市建设管理中不可或缺的重要组成部分.随着城市进程的加快及技术的进步,环卫工程管理也在逐渐向精细化.智能化.绿色化等趋势发展. 智能环卫依托物联网.AI.大数据等技术, ...
- 统计学习:EM算法及其在高斯混合模型(GMM)中的应用
1. EM算法的基本思想 我们在应用中所面对的数据有时是缺损的/观测不完全的[1][2].我们将数据分为: 可观测数据,用\(Y\)表示: 缺失数据,用\(Z\)表示; 完全数据,用\(X=(Y, Z ...
- C#的GroupBy方法是如何工作的
前言:先贴结果 GroupBy方法是如何工作的? 一.准备6个待分组的学生对象 class student { public string name;//姓名 public int grade;//年 ...
- [渗透测试] HTB_Surveillance WriteUp [上]
靶机:Surveillance (from Hack The Box) 工具:Kali Linux 目标:拿到user和root的一串32位hex字符串 ## 配置hosts 环境启动后,要设置 ...
- centos7下xfs文件系统的备份和恢复:完全备份,增量备份,差异备份
目录 一.关于xfs文件系统 二.xfsdump的备份级别和注意事项 三.完全备份整个目录/分区,然后恢复数据 四.完全备份分区中某个目录,然后恢复某个文件/文件夹 五.增量备份 一.关于xfs文件系 ...
- 【asp.net】滑块验证码(分享一个从github上下载的源码)
思路: 1. 准备好10张或20张不同规格的图片,按规格分类到不同文件夹,每个文件夹的图片从1开始顺序递增命名,为了随机选择图片. 2.前端提交规格比如200*300,根据规格选择原图,并初始化 ...
- 程序员面试金典-面试题 16.25. LRU缓存
题目: 设计和构建一个"最近最少使用"缓存,该缓存会删除最近最少使用的项目.缓存应该从键映射到值(允许你插入和检索特定键对应的值),并在初始化时指定最大容量.当缓存被填满时,它应该 ...
- linux系统下,安装mysql教程
1.查看mysql是否安装 首先我们需要查看软件是否已经安装,或者说查看安装的软件包名称.如查找是否安装mysql rpm -qa | grep mysql 2.卸载查到的软件 rpm -e --no ...
- String Record
T1. P5840 算法:ACAM+BIT+树链剖分 自然地,我们会对 \(s_i\) 建 ACAM,然后建出一颗 fail 树. 此时我们考虑集合内加入一个新的字符串.每一个匹配到的点我们都会给从这 ...