Django Programming error column does not exist even after running migrations

前端 未结 9 1028
南旧
南旧 2020-12-08 20:54

I run python manage.py makemigrations and I get: No changes detected Then, python manage.py migrate and I get: No migrations to apply.

9条回答
  •  眼角桃花
    2020-12-08 21:19

    My case might be a bit obscure, but if it helps someone, it is worth documenting here.

    I was calling a function in one of my migrations, which imported a Model of said migration regularly, i.e.

    from myApp.models import ModelX
    

    The only way models should be imported in migrations would be using e.g. RunPython:

    def myFunc(apps, schema_editor): 
        MyModel = apps.get_model('myApp 'MyModel')
    

    and then calling that function like so:

    class Migration(migrations.Migration):
        operations = [
            migrations.RunPython(initialize_mhs, reverse_code=migrations.RunPython.noop),
        ]
    

    Additionally the original import worked until I modified the model in a later migration, making this error harder to locate.

提交回复
热议问题