Django Migration Error: Column does not exist

后端 未结 15 2227
北恋
北恋 2020-12-10 10:25

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.

相关标签:
15条回答
  • 2020-12-10 11:13

    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.

    0 讨论(0)
  • 2020-12-10 11:14

    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)
    
    0 讨论(0)
  • 2020-12-10 11:15

    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.

    0 讨论(0)
提交回复
热议问题