On 07/07/2017 05:09 AM, Patryk Zawadzki wrote: > Right, and one reason for generating those "no-op" migrations is that > they aren't actually no-ops, if you value being able to write data > migrations in Python using the ORM. They keep the historical Python > models accurate. > > I would argue that this is a fairly optimistic view of the current state :) > > They are technically "historically accurate" but the point in history > they represent is not necessary the one you had in mind unless you only > have a single application and linear migrations (ie. no merge > migrations). Our current dependency system only allows you to express > "no sooner than X" but the graph solver can execute an arbitrary number > of later migrations between the one you depend on and the one you wrote. > > Imagine you have app A and migration M1 adds field F. You then create a > migration M2 in another application B that needs to access F so you have > it depend on (A, M1). Two months later field F is removed or renamed in > migration M3. Django has two ways to linearize the graph: (A, M1), (B, > M2), (A, M3) or (A, M1), (A, M3), (B, M2). Both are valid but the latter > will result in a crash when migrating from an empty DB state. In > practice we often have to add arbitrary dependencies to later migrations > to force a Python migration to execute in the correct order.
Yeah, that's an issue I've certainly run into. It's not _that_ unreasonable or arbitrary to solve this by adding a dependency of (A, M3) on (B, M2), but it would be better if we could express this as a "must-run-before" dependency on the B side (since the dependency of app B on app A may be one-way, and we shouldn't have to introduce knowledge of B into A's migrations -- and A may even be third-party). IMO this would be a reasonable feature addition. Carl -- 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 post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/042cd6a3-1e7c-b5a5-7909-2ef90f91c284%40oddbird.net. For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: OpenPGP digital signature