Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25168 closed Cleanup/optimization (fixed)

Document how to avoid foreign key constraint error after upgrade to 1.8

Reported by: Rachel Willmer Owned by: Rachel Willmer
Component: Documentation Version: 1.8
Severity: Normal Keywords: foreign key
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: yes UI/UX: no

Description

I hit this problem myself, and eventually figured out that it was because I hadn't created the fake install of the initial migrations for all my apps in my Django project.

I've seen and answered a few questions caused by this on StackOverflow, so I suspect it may be a common problem. e.g.

http://stackoverflow.com/questions/29483119/django-1-8-syncdb-not-working-throwing-a-foreign-key-constraint-error
http://stackoverflow.com/questions/28561458/django-mysql-error-when-creating-tables

Change History (7)

comment:1 by Rachel Willmer, 9 years ago

Owner: changed from nobody to Rachel Willmer
Status: newassigned

comment:2 by Rachel Willmer, 9 years ago

Suggested addition to https://docs.djangoproject.com/en/1.8/topics/migrations/#adding-migrations-to-apps (and the FAQ?)

Note: If you have upgraded to 1.8 or later from a previous version, and are getting a "Foreign Key constraint" error, check that you have created and fake-applied your initial migrations for all your apps. Without this, the tables will be created in the wrong order, which causes this error.

If you have made no migrations, then you can do this project-wide with:
$ python manage.py make migrations
$ python manage.py migrate --fake-initial

If you have made some, but not all, migrations, then you can do this on each remaining app with:
$ python manage.py make migrations your_app_label
$ python manage.py migrate --fake-initial your_app_label

comment:3 by Rachel Willmer, 9 years ago

Resolution: fixed
Status: assignedclosed

comment:4 by Tim Graham, 9 years ago

Has patch: set
Resolution: fixed
Status: closednew
Triage Stage: UnreviewedAccepted

Ticket isn't marked as fixed until the patch is merged.

comment:5 by Tim Graham, 9 years ago

Patch needs improvement: set

comment:6 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 70912e13:

Fixed #25168 -- Documented how to avoid foreign key constraint error after upgrading to 1.8.

comment:7 by Tim Graham <timograham@…>, 9 years ago

In 466950fa:

[1.8.x] Fixed #25168 -- Documented how to avoid foreign key constraint error after upgrading to 1.8.

Backport of 70912e137d5a6b089f35c662115fb758a00d7002 from master

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