#29000: RenameModel does not rename M2M column when run after
AlterField/RenameField
-------------------------------------+-------------------------------------
     Reporter:  David Nelson Adamec  |                    Owner:
                                     |  shangdahao
         Type:  Bug                  |                   Status:  assigned
    Component:  Migrations           |                  Version:  2.0
     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 David Nelson Adamec):

 After doing a little more digging, it appears that the `reload_model` with
 `delay=True` in the RenameField migration is the culprit. Because of the
 `delay` flag, only the original model and its directly related models
 (ModelA and ModelB in the example) are reloaded, so ModelC is untouched
 and its `b_set` field continues to point at the old version of ModelB
 that's no longer registered. Since ModelC isn't pointing at the new
 ModelB, it's not included in ModelB's `related_objects`.

 I'm not sure what the performance implication would be if delayed loading
 were removed from RenameField/AlterField, but I'm sure it's not good.
 Perhaps there's another clever solution out there, but I feel a bit out of
 my depth. Here's the workaround I'm using for the time being.

 {{{#!python
 class RenameModelWorkaround(migrations.RenameModel):
     def database_forwards(self, app_label, schema_editor, from_state,
 to_state):
         from_state.reload_model(app_label, self.old_name_lower)
         super(RenameModelWorkaround, self).database_forwards(
             app_label, schema_editor, from_state, to_state)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29000#comment:6>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.5ee47d848549ca8b431f133e65854ecc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to