Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading throws errors on migration because tables already exist #143

Closed
kelseyq opened this issue Mar 10, 2016 · 5 comments
Closed

Upgrading throws errors on migration because tables already exist #143

kelseyq opened this issue Mar 10, 2016 · 5 comments

Comments

@kelseyq
Copy link
Contributor

kelseyq commented Mar 10, 2016

Caused by #136
I recently upgraded from 1.5.0 to 1.6.0 and running migrate throws the error
django.db.utils.ProgrammingError: relation "axes_accessattempt" already exists
because it's trying to run the newly added migrations files even though the tables have already been created. This is especially hard to deal with on apps deployed to Heroku

@kelseyq
Copy link
Contributor Author

kelseyq commented Mar 10, 2016

It looks like this is due to 1.8 adding the --fake-initial flag, which used to be applied automatically?
https://docs.djangoproject.com/en/1.9/ref/django-admin/#cmdoption-migrate--fake-initial
Not sure how to fix

@camilonova
Copy link
Member

You can:

  1. Drop axes tables and let the migration creates them again
  2. Run ./manage.py migrate axes --fake

@kelseyq
Copy link
Contributor Author

kelseyq commented Mar 11, 2016

Proposed solution 1 both loses data that is potentially useful for forensics and disrupts functionality (resets cooloff time, etc.) The correct flag to add when migrating is --fake-initial, not -fake (I believe this would skip the change in 1.6.0 to add indexes.) #146 adds that to the changelog, so other users are aware.

@abhigyantiwari
Copy link

@camilonova What if we already have lots of data in the same table?

@aleksihakli
Copy link
Member

@abhigyantiwari This issue was closed over 2 years ago, is your question actually relevant?

Anyway, you can just run the correct migration with fake flag so Django records the migration as done and does not attempt to run the migration SQL. You can log the SQL axes runs by from the django.db logging handler and modify the contents of the migration to your liking, afterwards creating the migration records with the fake migration.

You can refer to e.g. this blog post on handling migrations yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants