#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 , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 9 years ago
comment:3 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:4 by , 9 years ago
Has patch: | set |
---|---|
Resolution: | fixed |
Status: | closed → new |
Triage Stage: | Unreviewed → Accepted |
Ticket isn't marked as fixed until the patch is merged.
comment:5 by , 9 years ago
Patch needs improvement: | set |
---|
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