From 697317f3340b1d1f40586262098ad4dbae9aebaf Mon Sep 17 00:00:00 2001 From: Matthew Wilkes Date: Mon, 16 Feb 2015 19:42:11 +0000 Subject: [PATCH] [1.8.x] Refs #24354 -- Prevented repointing of relations on superclasses when migrating a subclass's name change The issue was hidden on 1.8+ until #24573 due to a bug inside the model reloading process. Forwardport of patch from ae87ad005f7b62f5fa5a29ef07443fa1bbb9baf0 --- django/db/migrations/operations/models.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py index efd35f0501..2d75836da9 100644 --- a/django/db/migrations/operations/models.py +++ b/django/db/migrations/operations/models.py @@ -169,6 +169,10 @@ class RenameModel(Operation): state.remove_model(app_label, self.old_name_lower) # Repoint the FKs and M2Ms pointing to us for related_object in all_related_objects: + if related_object.model is not model: + # The model being renamed does not participate in this relation + # directly. Rather, a superclass does. + continue # Use the new related key for self referential related objects. if related_object.related_model == model: related_key = (app_label, self.new_name_lower)