#30570 closed Bug (invalid)
Integrity errors in Django project with custom User model.
Reported by: | siriuslan | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I am setting up a new django(version 2.2) project and want to use custom user model. When I load fixtures data, it failed with error like below:
django.db.utils.IntegrityError: Problem installing fixtures: insert or update on table "doctors_doctor" violates foreign key constraint "doctors_doctor_user_ptr_id_ba968804_fk_doctors_user_id" DETAIL: Key (user_ptr_id)=(1) is not present in table "doctors_user".
From django document - https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project I realized I did 'python manage.py migrate' before changing AUTH_USER_MODEL in settings.py. So I tried to delete all tables and redo 'python manage.py migrate', but it still hit this problem.
I can see there is another ticket - https://code.djangoproject.com/ticket/23297 complaining the same issue, I follow the solution for it but not working. No idea why.
Change History (2)
comment:1 by , 5 years ago
Component: | Uncategorized → Migrations |
---|---|
Resolution: | → worksforme |
Status: | new → closed |
Summary: | Integrity errors in Django project with custom User model → Integrity errors in Django project with custom User model. |
Type: | Uncategorized → Bug |
Version: | 2.2 → master |
comment:2 by , 5 years ago
Resolution: | worksforme → invalid |
---|
I figured how to make it work. I need 2 records in my json file, one is User and the other is my custom user. The pk value of these 2 should be the same.
Thanks for the report, however using a custom user model works for me. Please use one of support channels.