Document that migrations must have dependencies in order to access other apps' models
|Reported by:||Naddiseo||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When using 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)
Changed 12 months ago by Naddiseo
comment:1 Changed 12 months ago by Markush2010
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Resolution set to invalid
- Status changed from new to closed
- Type changed from New feature to Bug
comment:2 Changed 12 months ago by Naddiseo
- Resolution invalid deleted
- Status changed from closed to new
comment:3 Changed 12 months ago by timgraham
- Component changed from Migrations to Documentation
- Summary changed from Migration's project state does not include all models/apps to Document that migrations must have dependencies in order to access other apps' models
- Triage Stage changed from Unreviewed to Accepted
- Type changed from Bug to Cleanup/optimization