#36168: Backwards migration to replaced migration when other app has squashed
migrations can lead to FieldDoesNotExist error due to incorrect state
------------------------------------+------------------------------------
     Reporter:  Klaas van Schelven  |                    Owner:  (none)
         Type:  Bug                 |                   Status:  new
    Component:  Migrations          |                  Version:  5.1
     Severity:  Normal              |               Resolution:
     Keywords:                      |             Triage Stage:  Accepted
    Has patch:  0                   |      Needs documentation:  0
  Needs tests:  0                   |  Patch needs improvement:  0
Easy pickings:  0                   |                    UI/UX:  0
------------------------------------+------------------------------------
Comment (by Jacob Walls):

 Hi Klaas. Sorry if my shorthand was not helpful. What I meant was that I
 tested your suggested patch against your test project and found that I
 still couldn't migrate backward to 0001_initial, finding instead this
 exception:

 {{{#!py
   File "/Users/.../django/django/db/migrations/executor.py", line 229, in
 _migrate_all_backwards
     self.unapply_migration(states[migration], migration, fake=fake)
                            ~~~~~~^^^^^^^^^^^
 KeyError: <Migration triggerfailingcode.0002_baz_baz>
 }}}

 Because your patch (and the changes in #24900) take place inside a
 
[https://github.com/django/django/blob/14b46c1b848d846fad55c8634daeabd8787cf0d6/django/db/migrations/executor.py#L31
 loop over migration targets], by "pre-walking" I wondered if we could
 avoid rebuilding the graph during the loop and instead just derive
 whatever information we need to build the graph correctly only once, but I
 wasn't saying I had confidence in this hypothesis, I was just asking if
 you had already explored it. From the PR review comments in #24900 it
 appears the original version was quite different and perhaps more like
 what I'm suggesting now. (It's hard to say since I don't have the branch
 anymore.)

 Thanks for looking into it, I'd be glad to review a PR.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36168#comment:9>
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019504679117-c380cf5b-4303-4583-9b04-606c6d83c18f-000000%40eu-central-1.amazonses.com.

Reply via email to