#26488: migrate crashes when renaming a multi-table inheritance base model
-------------------------------------+-------------------------------------
Reporter: Christopher | Owner: nobody
Neugebauer |
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Nuwan Goonasekera):
Based on the patch proposed by Markus Holtermann, I've created a migration
operation that extends the existing RenameModel migration, and it seems to
be working as expected. Sharing in case someone else runs into the same
issue. I've only tested this with Django 2.1.7.
{{{
from django.db import migrations, models
class RenameModelAndBaseOperation(migrations.RenameModel):
def __init__(self, old_name, new_name):
super(RenameModelAndBaseOperation, self).__init__(old_name,
new_name)
def state_forwards(self, app_label, state):
old_remote_model = '%s.%s' % (app_label, self.old_name_lower)
new_remote_model = '%s.%s' % (app_label, self.new_name_lower)
to_reload = []
# change all bases affected by rename
for (model_app_label, model_name), model_state in
state.models.items():
if old_remote_model in model_state.bases:
new_bases_tuple = tuple(
new_remote_model if base == old_remote_model
else base
for base in model_state.bases)
state.models[model_app_label, model_name].bases =
new_bases_tuple
to_reload.append((model_app_label, model_name))
super(RenameModelAndBaseOperation, self).state_forwards(app_label,
state)
state.reload_models(to_reload, delay=True)
class Migration(migrations.Migration):
operations = [
RenameModelAndBaseOperation(
old_name='Cloud',
new_name='CloudOld',
),
]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26488#comment:17>
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/066.2f1d3e359bda46e810d008af2c2d076a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.