* Start a new project and create two apps myapp1 and myapp2
* Add a model named Model1 to myapp1
* Run makemigrations, resulting in 0001_initial.py that creates Model1
* Add a model named Model2 to myapp1
* Run makemigrations, resulting in 0002_model2.py that creates Model2
* Add a model named Model3 with a !ForeignKey to 'myapp1.Model2' to myapp2
* Run makemigrations, resulting in 0001_initial.py that creates Model3
The 0001_initial.py of myapp2 will then have `('myapp1', '__first__')` as
dependency while Model2 is created in the second migration.
--
Ticket URL: <https://code.djangoproject.com/ticket/22970>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Possibly related/duplicate of #22944.
--
Ticket URL: <https://code.djangoproject.com/ticket/22970#comment:1>
* owner: nobody => andrewgodwin
* status: new => assigned
Comment:
I suspect what's needed here is for the migration to depend on
``__last__``, which we definitely used to do and I backed out for some
reason.
--
Ticket URL: <https://code.djangoproject.com/ticket/22970#comment:2>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"008bff92b7028673cdab872a6733770606efce83"]:
{{{
#!CommitTicketReference repository=""
revision="008bff92b7028673cdab872a6733770606efce83"
Fixed #22970: Incorrect dependencies for existing migrated apps
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22970#comment:3>
Comment (by Andrew Godwin <andrew@…>):
In [changeset:"aba75e73db6a0baca1b721698ca24f026bb4a745"]:
{{{
#!CommitTicketReference repository=""
revision="aba75e73db6a0baca1b721698ca24f026bb4a745"
[1.7.x] Fixed #22970: Incorrect dependencies for existing migrated apps
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22970#comment:4>
* status: closed => new
* resolution: fixed =>
Comment:
Your fix didn't work, when I ran migrate I got the following error:
{{{
KeyError: u"Dependency references nonexistent parent node (u'myapp1',
u'__last__')"
}}}
It looks like {{{__last__}}} isn't implemented, there isn't any other
mention of it in the source. I took a look at the code and fixed it in a
different way: get the name of the app's last migration from the graph and
use that. I did some quick tests and everything seems to work fine.
Pull request: https://github.com/django/django/pull/2917
--
Ticket URL: <https://code.djangoproject.com/ticket/22970#comment:5>
* status: new => closed
* resolution: => fixed
Comment:
There was a typo and it should be `__latest__`; see #23008.
--
Ticket URL: <https://code.djangoproject.com/ticket/22970#comment:6>