解决IntegrityError: (1452, 'Cannot add or update a child row:a foreign key constraint fails

一、问题情境

在Django的后台添加用户时,报错如下:

IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (`mukewdb`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`))')

二、权宜之计

取消外检检查,但是之后还是要解决外检问题的

实际操作如下:

在settings文件中添加以下代码:

 'OPTIONS':{
                "init_command":"SET foreign_key_checks = 0;",
            }

即:

猜你喜欢

转载自blog.csdn.net/lezeqe/article/details/87378982