On Wed, 12 May 2021 09:37:53 -0700 (PDT)
"'Mike Lissner' via Django developers  (Contributions to Django
itself)" <django-developers@googlegroups.com> wrote:

> 
> I haven't done the manual approach but I imagine it's something like:
> 
> 1. Check your migrations across all apps with interdependencies for 
> RunPython or RunSQL code.
> 2. If found, make a decision about keeping or deleting that code.
> 3. Delete all migrations across all apps that have interdependencies.
> 4. Run the makemigrations command
> 5. Add your custom RunPython or RunSQL code back
> 

I've tried it. In my experience, it isn't as easy as described either.

When you have circular dependencies between the migration of apps, in
many (most?) cases it means you also have circular dependencies between
the models (FKs etc going in both directions). When that happens,
makemigrations from scratch doesn't do the right thing either --
basically, you need to recreate the interdependencies by having each
app's models created in two steps: One for the "core" of  the models,
so they all exist, and one for the relations, which can only be added
once all the referenced models are present.

The makemigrations command will only add one migration per app, and so
it cannot do this. I haven't tried this in a while, so I don't remember
if the command actually fails, or just produces non-working migrations
which you then need to edit by hand.

This all ties in to a discussion we had on the forum, about the
separation to apps in large projects (linking to my own post there, but
the whole discussion is worth a read if you haven't):
https://forum.djangoproject.com/t/why-do-we-need-apps/827/20

Have fun,
        Shai.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/20210813095124.33be923d.shai%40platonix.com.
  • Do ... 'Mike Lissner' via Django developers (Contributions to Django itself)
    • ... Matthew Pava
      • ... Kye Russell
        • ... Andrew Godwin
          • ... 'Mike Lissner' via Django developers (Contributions to Django itself)
            • ... 'Mike Lissner' via Django developers (Contributions to Django itself)
              • ... Ryan Hiebert
              • ... Hanne Moa
            • ... RenĂ© Fleschenberg
              • ... 'Mike Lissner' via Django developers (Contributions to Django itself)
            • ... Shai Berger
    • ... Raffaele Salmaso
    • ... Benny

Reply via email to