在使用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. JDK源码阅读-------自学笔记(七)(二维数组的浅析)

    实际开发中一般最多使用到二维数组,再高很少使用 二维数组很少用,实际开发中会使用容器代替使用 1.创建二维数组 1 // 二维数组初始化 2 int[][] secondDimensional = n ...

  2. C 语言编程 — GDB 调试工具

    目录 文章目录 目录 前文列表 代码调试 GDB 启动 GDB 交互命令 运行程序 暂停程序 设置断点 设置观察点 设置捕捉点 打印信息 查询运行信息 分割窗口 前文列表 <程序编译流程与 GC ...

  3. CentOS7 防火墙(firewall)的命令详解

    复制代码 安装:yum install firewalld 1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status ...

  4. Spring 对 Junit4,Junit5 的支持上的运用

    1. Spring 对 Junit4,Junit5 的支持上的运用 @ 目录 1. Spring 对 Junit4,Junit5 的支持上的运用 每博一文案 2. Spring对Junit4 的支持 ...

  5. C# Bitmap 在winform里编辑了,再次重新编辑,报gdi+错误解决办法

    经过排查,var bitmap=new Bitmap()这个局部对象,没有Dispose所致.虽然是局部的对象,但还是需要Dispose:

  6. jsonp原理详解——终于弄明白了JSONP

    什么是JSONP? 其实网上关于JSONP的讲解有很多,但却千篇一律,而且云里雾里,对于很多刚接触的人来讲理解起来有些困难,着用自己的方式来阐释一下这个问题,看看是否有帮助. 1.一个众所周知的问题, ...

  7. .netz 压缩 打包 成单EXE

    https://github.com/madebits/msnet-netz-compressor https://madebits.github.io/#r/msnet-netz-compresso ...

  8. Flask学习记录:在w3cschool资料的基础上的个人摘录、实践与总结

    学习与转载自w3cschool,在w3cschool资料的基础上的个人摘录.实践与总结,如有错误望留言. 一.Flask 概述 2021-08-25 14:01 更新 1.1 什么是Web Frame ...

  9. nginx分流配置

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

  10. windows下IPv4通信(C++、MFC)

    Cilect #include <stdio.h> #include <Ws2tcpip.h> #include <winsock2.h> #define HELL ...