mirror of
https://github.com/django/django.git
synced 2025-10-29 00:26:07 +00:00
Fixed #22853: Swapped models are now ignored for migration operations.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import router
|
||||
from django.db.models.fields import NOT_PROVIDED
|
||||
from django.utils import six
|
||||
from .base import Operation
|
||||
@@ -29,7 +28,7 @@ class AddField(Operation):
|
||||
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||
from_model = from_state.render().get_model(app_label, self.model_name)
|
||||
to_model = to_state.render().get_model(app_label, self.model_name)
|
||||
if router.allow_migrate(schema_editor.connection.alias, to_model):
|
||||
if self.allowed_to_migrate(schema_editor.connection.alias, to_model):
|
||||
field = to_model._meta.get_field_by_name(self.name)[0]
|
||||
if not self.preserve_default:
|
||||
field.default = self.field.default
|
||||
@@ -42,7 +41,7 @@ class AddField(Operation):
|
||||
|
||||
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
||||
from_model = from_state.render().get_model(app_label, self.model_name)
|
||||
if router.allow_migrate(schema_editor.connection.alias, from_model):
|
||||
if self.allowed_to_migrate(schema_editor.connection.alias, from_model):
|
||||
schema_editor.remove_field(from_model, from_model._meta.get_field_by_name(self.name)[0])
|
||||
|
||||
def describe(self):
|
||||
@@ -81,13 +80,13 @@ class RemoveField(Operation):
|
||||
|
||||
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||
from_model = from_state.render().get_model(app_label, self.model_name)
|
||||
if router.allow_migrate(schema_editor.connection.alias, from_model):
|
||||
if self.allowed_to_migrate(schema_editor.connection.alias, from_model):
|
||||
schema_editor.remove_field(from_model, from_model._meta.get_field_by_name(self.name)[0])
|
||||
|
||||
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
||||
from_model = from_state.render().get_model(app_label, self.model_name)
|
||||
to_model = to_state.render().get_model(app_label, self.model_name)
|
||||
if router.allow_migrate(schema_editor.connection.alias, to_model):
|
||||
if self.allowed_to_migrate(schema_editor.connection.alias, to_model):
|
||||
schema_editor.add_field(from_model, to_model._meta.get_field_by_name(self.name)[0])
|
||||
|
||||
def describe(self):
|
||||
@@ -118,7 +117,7 @@ class AlterField(Operation):
|
||||
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||
from_model = from_state.render().get_model(app_label, self.model_name)
|
||||
to_model = to_state.render().get_model(app_label, self.model_name)
|
||||
if router.allow_migrate(schema_editor.connection.alias, to_model):
|
||||
if self.allowed_to_migrate(schema_editor.connection.alias, to_model):
|
||||
from_field = from_model._meta.get_field_by_name(self.name)[0]
|
||||
to_field = to_model._meta.get_field_by_name(self.name)[0]
|
||||
# If the field is a relatedfield with an unresolved rel.to, just
|
||||
@@ -170,7 +169,7 @@ class RenameField(Operation):
|
||||
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||
from_model = from_state.render().get_model(app_label, self.model_name)
|
||||
to_model = to_state.render().get_model(app_label, self.model_name)
|
||||
if router.allow_migrate(schema_editor.connection.alias, to_model):
|
||||
if self.allowed_to_migrate(schema_editor.connection.alias, to_model):
|
||||
schema_editor.alter_field(
|
||||
from_model,
|
||||
from_model._meta.get_field_by_name(self.old_name)[0],
|
||||
@@ -180,7 +179,7 @@ class RenameField(Operation):
|
||||
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
||||
from_model = from_state.render().get_model(app_label, self.model_name)
|
||||
to_model = to_state.render().get_model(app_label, self.model_name)
|
||||
if router.allow_migrate(schema_editor.connection.alias, to_model):
|
||||
if self.allowed_to_migrate(schema_editor.connection.alias, to_model):
|
||||
schema_editor.alter_field(
|
||||
from_model,
|
||||
from_model._meta.get_field_by_name(self.new_name)[0],
|
||||
|
||||
Reference in New Issue
Block a user