1
0
mirror of https://github.com/django/django.git synced 2025-10-27 15:46:10 +00:00

Fixed #22568: Better proxy model support in migrations

This commit is contained in:
Andrew Godwin
2014-06-15 16:01:49 -07:00
parent a8ce5fdc28
commit c1276785f9
5 changed files with 220 additions and 39 deletions

View File

@@ -32,17 +32,17 @@ class CreateModel(Operation):
def database_forwards(self, app_label, schema_editor, from_state, to_state):
apps = to_state.render()
model = apps.get_model(app_label, self.name)
if router.allow_migrate(schema_editor.connection.alias, model):
if router.allow_migrate(schema_editor.connection.alias, model) and not model._meta.proxy:
schema_editor.create_model(model)
def database_backwards(self, app_label, schema_editor, from_state, to_state):
apps = from_state.render()
model = apps.get_model(app_label, self.name)
if router.allow_migrate(schema_editor.connection.alias, model):
if router.allow_migrate(schema_editor.connection.alias, model) and not model._meta.proxy:
schema_editor.delete_model(model)
def describe(self):
return "Create model %s" % (self.name, )
return "Create %smodel %s" % ("proxy " if self.options.get("proxy", False) else "", self.name)
def references_model(self, name, app_label=None):
strings_to_check = [self.name]
@@ -85,13 +85,13 @@ class DeleteModel(Operation):
def database_forwards(self, app_label, schema_editor, from_state, to_state):
apps = from_state.render()
model = apps.get_model(app_label, self.name)
if router.allow_migrate(schema_editor.connection.alias, model):
if router.allow_migrate(schema_editor.connection.alias, model) and not model._meta.proxy:
schema_editor.delete_model(model)
def database_backwards(self, app_label, schema_editor, from_state, to_state):
apps = to_state.render()
model = apps.get_model(app_label, self.name)
if router.allow_migrate(schema_editor.connection.alias, model):
if router.allow_migrate(schema_editor.connection.alias, model) and not model._meta.proxy:
schema_editor.create_model(model)
def references_model(self, name, app_label=None):