Python 3, Django 1.8.5, Postgres
I have a model Sites
that has been working fine. I recently tried to add a field, airport_code, and migrate the data.
In my case, that was because I had a unique_together constraint that was set.
When I wanted to remove a field, the auto-generated migration tried to remove the field before removing the unique_together constraint.
What I had to do was manually move up the migrations.AlterUniqueTogether constraint in the migration file, so that django removes first the constraint before trying to remove the field.
I hope this can help someone.
Late to the party, but there is some info I want to share. It helped me a lot! :)
I am using django-solo to store app config in database, and I got the same issue as Alex when adding new field to configuration model. Stacktrace pointed me to the line where I'm getting config from database: conf = SiteConfiguration().get_solo()
.
There is a closed issue for django-solo project on Github. The idea is to make model loading lazy (exactly as MrKickkiller pointed before).
So for modern Django version (in my case 3.0) this code works perfectly:
from django.utils.functional import SimpleLazyObject
conf = SimpleLazyObject(SiteConfiguration.get_solo)
Stuck into this issue recently.
In my case, I added a reference to a non-existing field in the code, then I came to the model file and added the new field, then tried to run makemigrations
command which thrown the above error.
So I went to the stack trace all the way up and found the newly added reference was the problem. commented that out, ran makemigrations
and voila.