django admin报错IntegrityError:'Cannot add or update a child row: a foreign key constraint fails'
2017-10-18 09:52
716 查看
如果在使用Django Admin后台添加用户时出现报错:
这时候需要在setting文件的databases中添加以下代码取消外键检查
2
完整的就是:
(1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxproject`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`))')1
这时候需要在setting文件的databases中添加以下代码取消外键检查
'OPTIONS':{ "init_command":"SET foreign_key_checks = 0;",1
2
完整的就是:
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;",
}
}
相关文章推荐
- 1452, 'Cannot add or update a child row: a foreign key constraint fails
- mysql添加外键失败:sql 1452 Cannot add or update a child row:a foreign key constraint fails
- Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails
- Cannot add or update a child row: a foreign key constraint fails (`mysql`.`ordermx`, CONSTRAINT `kf
- Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails
- MySql外键添加失败:java.ql.SQLException: 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 (`xx库`.`xx表`,
- Cannot add or update a child row: a foreign key constraint fails
- Cannot add or update a child row: a foreign key constraint fails 无法添加外键
- [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
- Cannot add or update a child row: a foreign key constraint fails 解决办法
- mysql添加外键失败:sql 1452 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
- 刷新数据库总是报错:不能增加或者更新约束, Cannot add or update a child row: a foreign key constraint fails
- Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails
- 解决1452- Cannot add or update a child rowa foreign key constraint fails问题
- IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constrai nt fails (`mxonline
- navicat中添加表外键显示Cannoot add or update a child row;a foreign key constraint fails
- [转][Err] 1452 - Cannot add or update a child row: a foreign key constraint fail