Ticket #27279: renamemodel-reset-apps.patch

File renamemodel-reset-apps.patch, 975 bytes (added by Marten Kenbeek, 6 years ago)
  • django/db/migrations/operations/models.py

    diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py
    index 027ebfe..2b449c2 100644
    a b class RenameModel(ModelOperation): 
    278278        )
    279279
    280280    def state_forwards(self, app_label, state):
     281        reset_apps = 'apps' not in state.__dict__
    281282        apps = state.apps
    282283        model = apps.get_model(app_label, self.old_name)
    283284        model._meta.apps = apps
    class RenameModel(ModelOperation): 
    335336                state.models[related_key].fields = new_fields
    336337                state.reload_model(*related_key)
    337338        state.reload_model(app_label, self.new_name_lower)
     339        if reset_apps:
     340            del state.__dict__['apps']
    338341
    339342    def database_forwards(self, app_label, schema_editor, from_state, to_state):
    340343        new_model = to_state.apps.get_model(app_label, self.new_name)
Back to Top