[Answered ]-Data Migrations on Django getting previous Model versions

2๐Ÿ‘

โœ…

Use the versioned app registry to get the model, rather than an import statement.

def my_migration(apps, schema_editor):
    MyModel = apps.get_model("my_app", "MyModel")

The first argument passed to your migration worker function is an app registry that has the historical versions of all your models loaded into it to match where in your history the migration sits.

๐Ÿ‘คwim

Leave a comment