Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#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 Mariusz Felisiak, 6 years ago

Component: UncategorizedMigrations
Resolution: worksforme
Status: newclosed
Summary: Integrity errors in Django project with custom User modelIntegrity errors in Django project with custom User model.
Type: UncategorizedBug
Version: 2.2master

Thanks for the report, however using a custom user model works for me. Please use one of support channels.

comment:2 by siriuslan, 6 years ago

Resolution: worksformeinvalid

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.

Note: See TracTickets for help on using tickets.
Back to Top