在使用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. css :not()选择器使用

    前言:这是一个vue的项目,引入了一个reset.css,重写了几乎所有标签的默认样式.项目中需要渲染富文本,里面包含了很多标签,例如:<h1>这是一个大标题</h1>,这个时 ...

  2. centos 文件系统权限

    模板:drwxrwxrwx r表是读 (Read) .w表示写 (Write) .x表示执行 (eXecute) 读.写.运行三项权限可以用数字表示,就是r=4,w=2,x=1, 777就是rwxrw ...

  3. Python:当函数做为参数时的技巧

    我们之前在<Python技法3: 匿名函数.回调函数.高阶函数>中提到,可以通过lambda表达式来为函数设置默认参数,从而修改函数的参数个数: import math def dista ...

  4. orangepi zero2在linux5.4以上内核使用ili9341

    背景 根据orangepi zero2用户手册说明,linux5.13内核不能使用 modprobe fbtft_device 驱动spi lcd 查看linux内核源码提交记录,发现在v5.4-rc ...

  5. 基于 ESP8266_RTOS_SDK 实现声控灯

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdint.h&g ...

  6. php的下载与安装

    一,进入到php的官方网站   https://www.php.net/   ,进入到下载页面: 选择 PHP 7.2.30 的Windows版本 具体的下载页面版本区分: 下载后,得到如下压缩包到如 ...

  7. flask blinker信号

    Flask框架中的信号基于blinker,其主要就是让开发者可是在flask请求过程中定制一些用户行为. pip3 install blinker 1.内置信号 request_started = _ ...

  8. 运算符优先级 JAVA11

    **运算符优先级 ** 规律:算术运算符优先级较高,关系和逻辑运算符优先级较低.多数运算符具有左结合性,单目运算符.三目运算符.赋值运算符具有右结合性. 运算符的优先级 举例 使用优先级为 1 的小括 ...

  9. CSS操作——边框属性

    1.border-style(边框风格) 定义边框的风格,值可以有: /* none:没有边框,当border的值为none的时候,系统将会忽略[border-color] hidden:隐藏边框,低 ...

  10. Android 12(S) MultiMedia Learning(七)NuPlayer GenericSource

    本节来看一下NuPlayer Source中的GenericSource,GenericSource主要是用来播放本地视频的,接下来着重来看以下5个方法: prepare,start,pause,se ...