1452, 'Cannot add or update a child row: a foreign key constraint fails

Django后台添加用户报错:1452, 'Cannot add or update a child row: a foreign key constraint fails

django.db.utils.IntegrityError: (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`))')
这时候需要在setting文件的databases中添加以下代码取消外键检查

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

猜你喜欢

转载自blog.csdn.net/topqy/article/details/89336593