#22932: "makemigrations" generates circular dependencies
-------------------------------------+-------------------------------------
     Reporter:  humitos              |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Migrations           |                  Version:  master
     Severity:  Normal               |               Resolution:  fixed
     Keywords:  circular             |             Triage Stage:
  dependency, migrations,            |  Unreviewed
  makemigrations                     |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by andrewgodwin):

 This is unavoidable, as Django can't detect swappable dependencies to
 resolve the loop at makemigrations time (thanks, swappable models!), but
 I've added some documentation to the custom user model docs to highlight
 that this might occur and how to fix it.

 The fix, incidentally, is to manually uncircularise the dependency loop.
 In this example, the dependency graph is:

 {{{
     team.TeamCaptain -> challenge.MyUser -> team.Team
                    \_________________________^
 }}}

 As you can see, this isn't actually circular, it's just that the start and
 end are in the same app and Django can't work out what app the middle one
 is in (as it's dynamic and can change based on project settings). The
 solution is to move the `TeamCaptain` model into a second migration in the
 `team` app, and make sure the migration dependencies are modified
 appropriately (i.e. that the `AUTH_USER_MODEL` dependency is also moved to
 that second migration). This will solve this case.

 The other possible case is when there actually is a dependency loop (e.g.
 two models have foreign keys pointing at each other). You can resolve this
 by splitting one ForeignKey off into a separate migration; just construct
 this situation without swappable models and run `makemigrations` and
 you'll get an example of how it's done.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22932#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.4c66a0df9d4e0ebad0186336d3631d7b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to