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.
--
Ticket URL: <https://code.djangoproject.com/ticket/34623>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => duplicate
Comment:
It's probably a duplicate of #23694.
--
Ticket URL: <https://code.djangoproject.com/ticket/34623#comment:1>
Comment (by Shai Berger):
Replying to [comment:1 Mariusz Felisiak]:
> It's probably a duplicate of #23694.
Yes, it is, but in the
[https://code.djangoproject.com/ticket/23694#comment:2 closing comment]
Andrew said "I'd love to know a way round it" and I believe I have
suggested one here.
--
Ticket URL: <https://code.djangoproject.com/ticket/34623#comment:2>
Comment (by Mariusz Felisiak):
Replying to [comment:2 Shai Berger]:
> Replying to [comment:1 Mariusz Felisiak]:
> > It's probably a duplicate of #23694.
>
> Yes, it is, but in the
[https://code.djangoproject.com/ticket/23694#comment:2 closing comment]
Andrew said "I'd love to know a way round it" and I believe I have
suggested one here.
Can you add a comment to the #23694? We should keep a discussion in the
single place.
--
Ticket URL: <https://code.djangoproject.com/ticket/34623#comment:3>