Document that migrations must have dependencies in order to access other apps' models
|Reported by:||Richard Eames||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
migrations.RunPython the first parameter passed to the function is documented as being equivalent to South's
orm['app.Model']. In South, the orm has a complete view of all the models, whereas the
app parameter only contains apps/models for which the current migration depends on.
I've attached a simple project. To demonstrate this issue, run
python manage.py migrate in the app.
The project contains 3 apps: spam, eggs, and cheese. There are dependencies between spam and eggs, but cheese is isolated. I created an empty migration in eggs, and print all the models I can find via the
apps parameter. I was expecting it to output all of the models in all three apps, but instead it only prints the models for which the migration depends on.
The apps models are as follows:
eggs: Egg (links to spam.Beef)
cheese: Cheese (no links)
spam: Beef (no links), Potato( links to spam.Beef)
I created an empty migration in eggs which lists all the models in the apps parameter, this is what it prints:
# print(cls) for cls in (for cls in apps.get_app_configs()) AppConfigStub: eggs class 'Egg' AppConfigSub: spam class 'Beef' class 'Potato' ---- # print(cls) for cls in apps.get_models() class 'Egg' class 'Beef' class 'Potato'
Notice how it neglects to print out anything from the 'cheese' app.
Change History (7)
comment:3 Changed 2 years ago by
|Component:||Migrations → Documentation|
|Summary:||Migration's project state does not include all models/apps → Document that migrations must have dependencies in order to access other apps' models|
|Triage Stage:||Unreviewed → Accepted|
|Type:||Bug → Cleanup/optimization|