Django Migration Error: Column does not exist

后端 未结 15 2329
北恋
北恋 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:49

    I ran into this problem recently after upgrading to Django 1.11. I wanted to permanently address the issue so I wouldn't have to comment / uncomment code every time I ran a migration on the table, so my approach:

    from django.db.utils import ProgrammingError as AvoidDataMigrationError
    
    try:
        ... do stuff that breaks migrations
    except AvoidDataMigrationError:
        pass
    

    I rename the exception during import to AvoidDataMigrationError so it's clear why it's there.

提交回复
热议问题