Fixed #29987 -- Detected unmanaged model deletions.

This commit is contained in:
Tim Fiedler 2018-11-26 22:26:40 +01:00 committed by Tim Graham
parent 8a1a919468
commit b07273a0f7
2 changed files with 5 additions and 4 deletions

View File

@ -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:

View File

@ -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(