解决django 新增加用户信息出现错误的问题
作者:Jabony 时间:2021-07-27 12:50:46
Python3.4版本
当我把新增加的用户信息填写完成后,点击保存,然后出现了这样的错误:
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_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`))')
外键约束。大概意思是:插入数据的时候,外键的值不是对应的主键的值。但是这时候表里是没有数据的,所以可能有主键值;插入数据时它的根节点可能不存在,所以插入失败。建议查询“外键”相关知识。两张表不是并列关系,而是父子关系。
配置数据库如下:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mxproject',
'USER':'root',
'PASSWORD':'123456',
'HOST':'127.0.0.1',
'PORT':'3306',
'OPTIONS':{
"init_command":"SET foreign_key_checks = 0;",
}
}
来源:https://blog.csdn.net/jabony/article/details/78237875
标签:django,增加,用户信息
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何用Matplotlib 画三维图的示例代码
2023-03-02 15:16:08
![](https://img.aspxhome.com/file/2023/2/118542_0s.png)
聊天室php&mysql(五)
2023-11-19 20:18:22
python实现壁纸批量下载代码实例
2023-11-15 12:38:54
![](https://img.aspxhome.com/file/2023/4/64594_0s.png)
python编辑用户登入界面的实现代码
2022-02-07 20:24:08
![](https://img.aspxhome.com/file/2023/4/99124_0s.png)
numba提升python运行速度的实例方法
2022-10-06 20:39:27
学习Python中一些实用的库
2022-11-02 13:55:56
![](https://img.aspxhome.com/file/2023/3/117343_0s.png)
对Tensorflow中权值和feature map的可视化详解
2021-03-31 22:24:39
![](https://img.aspxhome.com/file/2023/6/99276_0s.jpg)
小试Python中的pack()使用方法
2021-02-03 06:00:43
![](https://img.aspxhome.com/file/2023/6/90706_0s.png)
python数据写入Excel文件中的实现步骤
2023-11-19 23:11:45
使用Python对Access读写操作
2021-01-07 04:20:36
pygame游戏之旅 如何制作游戏障碍
2021-03-05 00:16:28
![](https://img.aspxhome.com/file/2023/7/87757_0s.png)
微信小程序输入多行文本的实战记录
2023-09-10 15:29:51
![](https://img.aspxhome.com/file/2023/1/56311_0s.png)
Python word实现读取及导出代码解析
2021-05-11 07:56:47
![](https://img.aspxhome.com/file/2023/1/124921_0s.png)
判断浏览器是否接受 Cookie
2009-07-28 17:52:00
用python实现的去除win下文本文件头部BOM的代码
2021-04-01 08:00:19
python实现将一个数组逆序输出的方法
2022-07-16 11:07:51
Python退出时强制运行一段代码的实现方法
2021-02-07 08:04:16
![](https://img.aspxhome.com/file/2023/7/102837_0s.jpg)
详解selenium + chromedriver 被反爬的解决方法
2022-03-20 18:40:46
Python数据分析与处理(二)——处理中国地区信息
2021-04-04 17:12:26
![](https://img.aspxhome.com/file/2023/0/90440_0s.jpg)
SQL Server开发过程中的的常见问题总结
2009-01-06 11:16:00