inconsistent migration history when changing a django app's name
Solution 1
I think you already run migration named version_1.0001_initial before you renamed app to beta. All you need is to update database records in the table django_migrations and rename old app migrations to the new name using this SQL statement:
UPDATE django_migrations SET app = 'beta' WHERE app = 'version_1';
Solution 2
For what it's worth, and if it helps anyone in a similar situation:
I had this issue when copying over a correct database from the production server to a test instance, to emulate the data on it, so I knew the database was correct. I haven't dug down into why this set the migrations out of line, but (and I want to emphasize that I could easily experiment on this because I had data backed up) just emptying the django_migrations
table and running python manage.py migrations <app_name> --fake
solved it for me.
Admin
Updated on August 06, 2022Comments
-
Admin over 1 year
I'm trying to rename one of the apps in my django website. There is another app which depends on it and its mysql tables. I went over all the files in both apps and changed the instances of the old name to the new one.
However, now I encounter this error message when trying to perform a migration:
File "/Users/Limor/anaconda/lib/python2.7/site-packages/Django-1.10a1-py2.7.egg/django/db/migrations/loader.py", line 287, in check_consistent_history migration[0], migration[1], parent[0], parent[1], django.db.migrations.exceptions.InconsistentMigrationHistory: Migration manual_tasks.0001_initial is applied before its dependency beta.0001_initial
I couldn't find a solution for this issue, and if I tried to comment out the particular function which raises the exception I run into related issues down the road. Am I doomed, or is there a way to fix it?
Thanks!
EDIT:
the old name is version_1, the new is beta and the other app which relies on it is manual_tasks.
Here's the code's structure:
~/website/ |-- .ebextensions | `-- django.config |-- project | |-- __init__.py | |-- local_settings.py | |-- settings.py | |-- urls.py | `-- wsgi.py |-- db.sqlite3 |-- manage.py |--beta | |-- __init__.py | |-- admin.py | |-- apps.py | |-- local_settings.py | |-- models.py | |-- tests.py | |-- urls.py | |-- views.py | |-- migrations | |-- __init__.py | |-- 0001__initial.py | |-- static | |-- assets | |-- images | |-- templates |--manual_tasks | |-- __init__.py | |-- admin.py | |-- apps.py | |-- models.py | |-- tests.py | |-- urls.py | |-- views.py | |-- migrations | |-- __init__.py | |-- 0001__initial.py | |-- static | |-- assets | |-- images | |-- templates `-- requirements.txt
Hope it makes more sense!