From b07273a0f710c0ed00ccbc1c555b4f1e5d6fc662 Mon Sep 17 00:00:00 2001 From: Tim Fiedler Date: Mon, 26 Nov 2018 22:26:40 +0100 Subject: [PATCH] Fixed #29987 -- Detected unmanaged model deletions. --- django/db/migrations/autodetector.py | 4 ---- tests/migrations/test_autodetector.py | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index fa63745b48..3d3eeb9230 100644 --- a/django/db/migrations/autodetector.py +++ b/django/db/migrations/autodetector.py @@ -722,10 +722,6 @@ class MigrationAutodetector: for app_label, model_name in all_deleted_models: model_state = self.from_state.models[app_label, model_name] model = self.old_apps.get_model(app_label, model_name) - if not model._meta.managed: - # Skip here, no need to handle fields for unmanaged models - continue - # Gather related fields related_fields = {} for field in model._meta.local_fields: diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index 7a6a990b12..b52852fb52 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -1662,6 +1662,11 @@ class AutodetectorTests(TestCase): self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel"]) self.assertOperationAttributes(changes, 'testapp', 0, 0, name="AuthorUnmanaged", options={"managed": False}) + def test_unmanaged_delete(self): + changes = self.get_changes([self.author_empty, self.author_unmanaged], [self.author_empty]) + self.assertNumberMigrations(changes, 'testapp', 1) + self.assertOperationTypes(changes, 'testapp', 0, ['DeleteModel']) + def test_unmanaged_to_managed(self): # Now, we test turning an unmanaged model into a managed model changes = self.get_changes(