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

如果在使用Django Admin后台添加用户时出现报错:

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;",
}

你可能感兴趣的:(Django后台添加用户报错:1452, 'Cannot add or update a child row: a foreign key constraint fails)