8π
The solution which worked for me is to delete my migrations folder and database completely thereafter running following commands-
python manage.py makemigrations
python manage.py migrate
because this error occured to me due to some misplacement of foreign key, and I was getting the error even after undoing the changes.
We are deleting the migration folder in the app because the actual problem is with that folder and there is nothing special in migration folder and it will be recreated using your model.py file running the command βpython manage.py makemigrations. The solution is just to delete the Migration folder and recreate it using commands.
So what you have to do-
- Delete migration folder from the app.
- Run the commands python manage.py makemigrations and then python manage.py migrate
Caution: The data in the database will be lost after this, So perform this only if your data is not important.
2π
This is how I solved this problem:
- Create a new
ForeignKey
calltmp
to your related model. Run a migration. - Delete the old
ForeignKey
and run a migration. - Rename
tmp
to whatever the oldForeignKey
was called. Run a migration.
So, you end up having three migration files to do one thing but at least it does it!
- [Django]-How to call multiple views on one url in pinax
- [Django]-Saving post from tweepy to django model in a good way
- [Django]-Docker replicas vs gunicorn workers in production
2π
This problem is caused by cyclic dependency in your migrations. Some other migration that is run prior to the latest migration is calling a migration that reinstates the state before model rename. For example, you renamed model foo
to bar
in xyzzy.migrations.0004_rename
but during applying migrations, after xyzzy.migrations.0004_rename
runs bozotic.0002_bozo
that depends on xyzzy.migrations.0001_initial
thus the migration that has to be applied now doesnβt see the state created by xyzzy.migrations.004_rename
.
Took me an hour to debug and fix this error in my project.
Check your migration dependencies and try manually adjusting dependencies so that when running the migration models are in the desired state
- [Django]-How to deal with unstable data received from RFID reader?
- [Django]-Django 1.3 β can't register my custom UserAdmin
- [Django]-Spam proof hit counter in Django