﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34623	Swappable dependencies always depend on first migration of app	Shai Berger	nobody	"This is a spin-off from https://github.com/django/django/pull/16861 and #23528.

When a migration specifies a swappable dependency, it is given as {{{""app_label.Model""}}}. But at run-time that gets translated into {{{""app_label.__first__""}}}, and the model name is ignored. This works as long as the model is defined by the time the dependent migration is run, but if the model is not created in the first migration of its app, then the right order of execution is no longer guaranteed.

This problem, if it manifests, is not at the level of either of the apps, but only the project.

The ideal solution is that a swappable dependency will actually mean ""migrate that other app until the model shows up"". That seems incompatible with making a migration plan in advance.

Another solution may be to load the app's migrations and look for a suitable `CreateModel` operation. That is not ideal, because models can be created by other operations (obviously the built-in `RenameModel`, but even an `AddField` with a M2M, not to mention 3rd-party operations).

A different approach would be just to check -- when a swappable dependency is in place, after running the initial migration of the dependency app, verify that the requested model exists, and if it doesn't, error out. That may later be extended, by allowing a specific migration to marked (explicitly, in its code) as providing a specific model, but that extension may well be a YAGNI."	Cleanup/optimization	closed	Migrations	dev	Normal	duplicate			Unreviewed	0	0	0	0	0	0
