Django Migration Error: Column does not exist

后端 未结 15 2333
北恋
北恋 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 10:53

    Just now had the same error when I tried to migrate a SingletonModel to actually contain the necessary fields.

    Reason for the error was that my Model A used some fields of this SingletonModel (as configurable values). And during instantation of model A during the migration process it obviously couldn't guarantee that my migration was safe.

    A colleague had a wonderful idea. Make the default value for the field a function call, and therefor lazy.

    Example:

    class A (models.Model):
        default_value = models.DecimalField(default: lambda: SingletonModel.get_solo().value, ...)
    

    So therefor, my advice: Try and make the offending call (seen in stacktrace) a lazy one.

提交回复
热议问题