mirror of https://github.com/django/django.git
Fixed #29987 -- Detected unmanaged model deletions.
This commit is contained in:
parent
8a1a919468
commit
b07273a0f7
|
@ -722,10 +722,6 @@ class MigrationAutodetector:
|
||||||
for app_label, model_name in all_deleted_models:
|
for app_label, model_name in all_deleted_models:
|
||||||
model_state = self.from_state.models[app_label, model_name]
|
model_state = self.from_state.models[app_label, model_name]
|
||||||
model = self.old_apps.get_model(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
|
# Gather related fields
|
||||||
related_fields = {}
|
related_fields = {}
|
||||||
for field in model._meta.local_fields:
|
for field in model._meta.local_fields:
|
||||||
|
|
|
@ -1662,6 +1662,11 @@ class AutodetectorTests(TestCase):
|
||||||
self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel"])
|
self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel"])
|
||||||
self.assertOperationAttributes(changes, 'testapp', 0, 0, name="AuthorUnmanaged", options={"managed": False})
|
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):
|
def test_unmanaged_to_managed(self):
|
||||||
# Now, we test turning an unmanaged model into a managed model
|
# Now, we test turning an unmanaged model into a managed model
|
||||||
changes = self.get_changes(
|
changes = self.get_changes(
|
||||||
|
|
Loading…
Reference in New Issue