2017-06-30 20:35:58 +08:00
|
|
|
from django.core.exceptions import FieldDoesNotExist
|
2019-08-20 15:54:41 +08:00
|
|
|
from django.db.models import NOT_PROVIDED
|
2015-01-02 23:37:21 +08:00
|
|
|
from django.utils.functional import cached_property
|
2015-01-28 20:35:27 +08:00
|
|
|
|
2013-05-30 00:47:10 +08:00
|
|
|
from .base import Operation
|
2020-04-04 04:38:06 +08:00
|
|
|
from .utils import field_is_referenced, field_references, get_references
|
2013-05-30 00:47:10 +08:00
|
|
|
|
|
|
|
|
2016-01-09 15:36:09 +08:00
|
|
|
class FieldOperation(Operation):
|
2017-02-03 11:09:12 +08:00
|
|
|
def __init__(self, model_name, name, field=None):
|
2013-11-06 21:47:58 +08:00
|
|
|
self.model_name = model_name
|
2013-05-30 00:47:10 +08:00
|
|
|
self.name = name
|
2017-02-03 11:09:12 +08:00
|
|
|
self.field = field
|
2016-01-09 15:36:09 +08:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def model_name_lower(self):
|
|
|
|
return self.model_name.lower()
|
2013-05-30 00:47:10 +08:00
|
|
|
|
2015-01-02 23:37:21 +08:00
|
|
|
@cached_property
|
|
|
|
def name_lower(self):
|
|
|
|
return self.name.lower()
|
|
|
|
|
2016-01-09 15:36:09 +08:00
|
|
|
def is_same_model_operation(self, operation):
|
|
|
|
return self.model_name_lower == operation.model_name_lower
|
|
|
|
|
|
|
|
def is_same_field_operation(self, operation):
|
|
|
|
return self.is_same_model_operation(operation) and self.name_lower == operation.name_lower
|
|
|
|
|
2020-04-04 11:05:16 +08:00
|
|
|
def references_model(self, name, app_label):
|
2017-01-31 02:43:20 +08:00
|
|
|
name_lower = name.lower()
|
|
|
|
if name_lower == self.model_name_lower:
|
|
|
|
return True
|
2017-02-03 11:09:12 +08:00
|
|
|
if self.field:
|
2020-04-04 04:38:06 +08:00
|
|
|
return bool(field_references(
|
2020-04-04 12:38:15 +08:00
|
|
|
(app_label, self.model_name_lower), self.field, (app_label, name_lower)
|
2020-04-04 04:38:06 +08:00
|
|
|
))
|
2017-02-17 01:50:43 +08:00
|
|
|
return False
|
2016-03-04 06:16:22 +08:00
|
|
|
|
2020-04-04 11:05:16 +08:00
|
|
|
def references_field(self, model_name, name, app_label):
|
2017-02-03 14:32:53 +08:00
|
|
|
model_name_lower = model_name.lower()
|
|
|
|
# Check if this operation locally references the field.
|
|
|
|
if model_name_lower == self.model_name_lower:
|
|
|
|
if name == self.name:
|
|
|
|
return True
|
|
|
|
elif self.field and hasattr(self.field, 'from_fields') and name in self.field.from_fields:
|
|
|
|
return True
|
|
|
|
# Check if this operation remotely references the field.
|
2020-04-04 04:38:06 +08:00
|
|
|
if self.field is None:
|
|
|
|
return False
|
|
|
|
return bool(field_references(
|
|
|
|
(app_label, self.model_name_lower),
|
|
|
|
self.field,
|
|
|
|
(app_label, model_name_lower),
|
|
|
|
name,
|
|
|
|
))
|
2017-02-03 14:32:53 +08:00
|
|
|
|
2020-04-04 10:57:42 +08:00
|
|
|
def reduce(self, operation, app_label):
|
2016-01-09 16:12:46 +08:00
|
|
|
return (
|
2020-04-04 10:57:42 +08:00
|
|
|
super().reduce(operation, app_label) or
|
2016-01-09 16:12:46 +08:00
|
|
|
not operation.references_field(self.model_name, self.name, app_label)
|
|
|
|
)
|
2016-01-09 15:36:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
class AddField(FieldOperation):
|
2017-01-25 07:04:12 +08:00
|
|
|
"""Add a field to a model."""
|
2016-01-09 15:36:09 +08:00
|
|
|
|
|
|
|
def __init__(self, model_name, name, field, preserve_default=True):
|
|
|
|
self.preserve_default = preserve_default
|
2017-02-03 11:09:12 +08:00
|
|
|
super().__init__(model_name, name, field)
|
2015-01-02 23:37:21 +08:00
|
|
|
|
2014-11-16 03:25:43 +08:00
|
|
|
def deconstruct(self):
|
2014-11-23 01:57:13 +08:00
|
|
|
kwargs = {
|
|
|
|
'model_name': self.model_name,
|
|
|
|
'name': self.name,
|
|
|
|
'field': self.field,
|
|
|
|
}
|
2014-11-16 03:25:43 +08:00
|
|
|
if self.preserve_default is not True:
|
|
|
|
kwargs['preserve_default'] = self.preserve_default
|
|
|
|
return (
|
|
|
|
self.__class__.__name__,
|
2014-11-23 01:57:13 +08:00
|
|
|
[],
|
2014-11-16 03:25:43 +08:00
|
|
|
kwargs
|
|
|
|
)
|
|
|
|
|
2013-05-30 00:47:10 +08:00
|
|
|
def state_forwards(self, app_label, state):
|
2013-12-04 21:56:22 +08:00
|
|
|
# If preserve default is off, don't use the default for future state
|
|
|
|
if not self.preserve_default:
|
|
|
|
field = self.field.clone()
|
|
|
|
field.default = NOT_PROVIDED
|
|
|
|
else:
|
|
|
|
field = self.field
|
2020-04-22 11:14:34 +08:00
|
|
|
state.models[app_label, self.model_name_lower].fields[self.name] = field
|
2016-11-06 19:03:05 +08:00
|
|
|
# Delay rendering of relationships if it's not a relational field
|
|
|
|
delay = not field.is_relation
|
|
|
|
state.reload_model(app_label, self.model_name_lower, delay=delay)
|
2013-05-30 00:47:10 +08:00
|
|
|
|
|
|
|
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
2014-11-05 17:43:31 +08:00
|
|
|
to_model = to_state.apps.get_model(app_label, self.model_name)
|
2015-02-19 15:27:58 +08:00
|
|
|
if self.allow_migrate_model(schema_editor.connection.alias, to_model):
|
2014-11-05 17:43:31 +08:00
|
|
|
from_model = from_state.apps.get_model(app_label, self.model_name)
|
2015-01-07 08:16:35 +08:00
|
|
|
field = to_model._meta.get_field(self.name)
|
2014-01-20 01:42:29 +08:00
|
|
|
if not self.preserve_default:
|
|
|
|
field.default = self.field.default
|
|
|
|
schema_editor.add_field(
|
|
|
|
from_model,
|
|
|
|
field,
|
|
|
|
)
|
|
|
|
if not self.preserve_default:
|
|
|
|
field.default = NOT_PROVIDED
|
2013-05-30 00:47:10 +08:00
|
|
|
|
|
|
|
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
2014-11-05 17:43:31 +08:00
|
|
|
from_model = from_state.apps.get_model(app_label, self.model_name)
|
2015-02-19 15:27:58 +08:00
|
|
|
if self.allow_migrate_model(schema_editor.connection.alias, from_model):
|
2015-01-07 08:16:35 +08:00
|
|
|
schema_editor.remove_field(from_model, from_model._meta.get_field(self.name))
|
2013-05-30 00:47:10 +08:00
|
|
|
|
2013-06-19 23:23:52 +08:00
|
|
|
def describe(self):
|
|
|
|
return "Add field %s to %s" % (self.name, self.model_name)
|
|
|
|
|
2020-04-04 10:57:42 +08:00
|
|
|
def reduce(self, operation, app_label):
|
2016-01-09 15:36:09 +08:00
|
|
|
if isinstance(operation, FieldOperation) and self.is_same_field_operation(operation):
|
|
|
|
if isinstance(operation, AlterField):
|
|
|
|
return [
|
|
|
|
AddField(
|
|
|
|
model_name=self.model_name,
|
|
|
|
name=operation.name,
|
|
|
|
field=operation.field,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
elif isinstance(operation, RemoveField):
|
|
|
|
return []
|
|
|
|
elif isinstance(operation, RenameField):
|
|
|
|
return [
|
|
|
|
AddField(
|
|
|
|
model_name=self.model_name,
|
|
|
|
name=operation.new_name,
|
|
|
|
field=self.field,
|
|
|
|
),
|
|
|
|
]
|
2020-04-04 10:57:42 +08:00
|
|
|
return super().reduce(operation, app_label)
|
2016-01-09 15:36:09 +08:00
|
|
|
|
2013-05-30 00:47:10 +08:00
|
|
|
|
2016-01-09 15:36:09 +08:00
|
|
|
class RemoveField(FieldOperation):
|
2017-01-25 07:04:12 +08:00
|
|
|
"""Remove a field from a model."""
|
2013-05-30 00:47:10 +08:00
|
|
|
|
2014-11-16 03:25:43 +08:00
|
|
|
def deconstruct(self):
|
2014-11-23 01:57:13 +08:00
|
|
|
kwargs = {
|
|
|
|
'model_name': self.model_name,
|
|
|
|
'name': self.name,
|
|
|
|
}
|
2014-11-16 03:25:43 +08:00
|
|
|
return (
|
|
|
|
self.__class__.__name__,
|
2014-11-23 01:57:13 +08:00
|
|
|
[],
|
|
|
|
kwargs
|
2014-11-16 03:25:43 +08:00
|
|
|
)
|
|
|
|
|
2013-05-30 00:47:10 +08:00
|
|
|
def state_forwards(self, app_label, state):
|
2020-04-22 11:14:34 +08:00
|
|
|
model_state = state.models[app_label, self.model_name_lower]
|
|
|
|
old_field = model_state.fields.pop(self.name)
|
2016-11-06 19:03:05 +08:00
|
|
|
# Delay rendering of relationships if it's not a relational field
|
|
|
|
delay = not old_field.is_relation
|
|
|
|
state.reload_model(app_label, self.model_name_lower, delay=delay)
|
2013-05-30 00:47:10 +08:00
|
|
|
|
|
|
|
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
2014-11-05 17:43:31 +08:00
|
|
|
from_model = from_state.apps.get_model(app_label, self.model_name)
|
2015-02-19 15:27:58 +08:00
|
|
|
if self.allow_migrate_model(schema_editor.connection.alias, from_model):
|
2015-01-07 08:16:35 +08:00
|
|
|
schema_editor.remove_field(from_model, from_model._meta.get_field(self.name))
|
2013-05-30 00:47:10 +08:00
|
|
|
|
|
|
|
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
2014-11-05 17:43:31 +08:00
|
|
|
to_model = to_state.apps.get_model(app_label, self.model_name)
|
2015-02-19 15:27:58 +08:00
|
|
|
if self.allow_migrate_model(schema_editor.connection.alias, to_model):
|
2014-11-05 17:43:31 +08:00
|
|
|
from_model = from_state.apps.get_model(app_label, self.model_name)
|
2015-01-07 08:16:35 +08:00
|
|
|
schema_editor.add_field(from_model, to_model._meta.get_field(self.name))
|
2013-06-19 23:23:52 +08:00
|
|
|
|
|
|
|
def describe(self):
|
|
|
|
return "Remove field %s from %s" % (self.name, self.model_name)
|
2013-06-20 22:12:59 +08:00
|
|
|
|
2020-04-04 10:57:42 +08:00
|
|
|
def reduce(self, operation, app_label):
|
2017-02-03 11:09:12 +08:00
|
|
|
from .models import DeleteModel
|
|
|
|
if isinstance(operation, DeleteModel) and operation.name_lower == self.model_name_lower:
|
|
|
|
return [operation]
|
2020-04-04 10:57:42 +08:00
|
|
|
return super().reduce(operation, app_label)
|
2017-02-03 11:09:12 +08:00
|
|
|
|
2013-06-20 22:12:59 +08:00
|
|
|
|
2016-01-09 15:36:09 +08:00
|
|
|
class AlterField(FieldOperation):
|
2013-06-20 22:12:59 +08:00
|
|
|
"""
|
2017-01-25 07:04:12 +08:00
|
|
|
Alter a field's database column (e.g. null, max_length) to the provided
|
|
|
|
new field.
|
2013-06-20 22:12:59 +08:00
|
|
|
"""
|
|
|
|
|
2014-11-23 13:29:23 +08:00
|
|
|
def __init__(self, model_name, name, field, preserve_default=True):
|
2014-10-07 07:53:21 +08:00
|
|
|
self.preserve_default = preserve_default
|
2017-02-03 11:09:12 +08:00
|
|
|
super().__init__(model_name, name, field)
|
2015-01-02 23:37:21 +08:00
|
|
|
|
2014-11-16 03:25:43 +08:00
|
|
|
def deconstruct(self):
|
2014-11-23 01:57:13 +08:00
|
|
|
kwargs = {
|
|
|
|
'model_name': self.model_name,
|
|
|
|
'name': self.name,
|
|
|
|
'field': self.field,
|
|
|
|
}
|
2014-11-16 03:25:43 +08:00
|
|
|
if self.preserve_default is not True:
|
|
|
|
kwargs['preserve_default'] = self.preserve_default
|
|
|
|
return (
|
|
|
|
self.__class__.__name__,
|
2014-11-23 01:57:13 +08:00
|
|
|
[],
|
2014-11-16 03:25:43 +08:00
|
|
|
kwargs
|
|
|
|
)
|
|
|
|
|
2013-06-20 22:12:59 +08:00
|
|
|
def state_forwards(self, app_label, state):
|
2014-10-07 07:53:21 +08:00
|
|
|
if not self.preserve_default:
|
|
|
|
field = self.field.clone()
|
|
|
|
field.default = NOT_PROVIDED
|
|
|
|
else:
|
|
|
|
field = self.field
|
2020-04-22 11:14:34 +08:00
|
|
|
model_state = state.models[app_label, self.model_name_lower]
|
|
|
|
model_state.fields[self.name] = field
|
2016-11-06 19:03:05 +08:00
|
|
|
# TODO: investigate if old relational fields must be reloaded or if it's
|
|
|
|
# sufficient if the new field is (#27737).
|
2017-07-01 02:51:08 +08:00
|
|
|
# Delay rendering of relationships if it's not a relational field and
|
|
|
|
# not referenced by a foreign key.
|
|
|
|
delay = (
|
|
|
|
not field.is_relation and
|
2020-04-04 04:38:06 +08:00
|
|
|
not field_is_referenced(
|
|
|
|
state, (app_label, self.model_name_lower), (self.name, field),
|
|
|
|
)
|
2017-07-01 02:51:08 +08:00
|
|
|
)
|
2016-11-06 19:03:05 +08:00
|
|
|
state.reload_model(app_label, self.model_name_lower, delay=delay)
|
2013-06-20 22:12:59 +08:00
|
|
|
|
|
|
|
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
2014-11-05 17:43:31 +08:00
|
|
|
to_model = to_state.apps.get_model(app_label, self.model_name)
|
2015-02-19 15:27:58 +08:00
|
|
|
if self.allow_migrate_model(schema_editor.connection.alias, to_model):
|
2014-11-05 17:43:31 +08:00
|
|
|
from_model = from_state.apps.get_model(app_label, self.model_name)
|
2015-01-07 08:16:35 +08:00
|
|
|
from_field = from_model._meta.get_field(self.name)
|
|
|
|
to_field = to_model._meta.get_field(self.name)
|
2014-10-07 07:53:21 +08:00
|
|
|
if not self.preserve_default:
|
|
|
|
to_field.default = self.field.default
|
2014-03-11 10:52:29 +08:00
|
|
|
schema_editor.alter_field(from_model, from_field, to_field)
|
2014-10-07 07:53:21 +08:00
|
|
|
if not self.preserve_default:
|
|
|
|
to_field.default = NOT_PROVIDED
|
2013-06-20 22:12:59 +08:00
|
|
|
|
|
|
|
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
|
|
|
self.database_forwards(app_label, schema_editor, from_state, to_state)
|
|
|
|
|
|
|
|
def describe(self):
|
|
|
|
return "Alter field %s on %s" % (self.name, self.model_name)
|
|
|
|
|
2020-04-04 10:57:42 +08:00
|
|
|
def reduce(self, operation, app_label):
|
2016-01-09 15:36:09 +08:00
|
|
|
if isinstance(operation, RemoveField) and self.is_same_field_operation(operation):
|
|
|
|
return [operation]
|
|
|
|
elif isinstance(operation, RenameField) and self.is_same_field_operation(operation):
|
|
|
|
return [
|
|
|
|
operation,
|
|
|
|
AlterField(
|
|
|
|
model_name=self.model_name,
|
|
|
|
name=operation.new_name,
|
|
|
|
field=self.field,
|
|
|
|
),
|
|
|
|
]
|
2020-04-04 10:57:42 +08:00
|
|
|
return super().reduce(operation, app_label)
|
2016-01-09 15:36:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
class RenameField(FieldOperation):
|
2017-01-25 07:04:12 +08:00
|
|
|
"""Rename a field on the model. Might affect db_column too."""
|
2013-06-20 22:12:59 +08:00
|
|
|
|
2014-11-23 13:29:23 +08:00
|
|
|
def __init__(self, model_name, old_name, new_name):
|
2013-06-20 22:12:59 +08:00
|
|
|
self.old_name = old_name
|
|
|
|
self.new_name = new_name
|
2017-01-21 21:13:44 +08:00
|
|
|
super().__init__(model_name, old_name)
|
2013-06-20 22:12:59 +08:00
|
|
|
|
2015-01-02 23:37:21 +08:00
|
|
|
@cached_property
|
|
|
|
def old_name_lower(self):
|
|
|
|
return self.old_name.lower()
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def new_name_lower(self):
|
|
|
|
return self.new_name.lower()
|
|
|
|
|
2014-11-16 03:25:43 +08:00
|
|
|
def deconstruct(self):
|
2014-11-23 01:57:13 +08:00
|
|
|
kwargs = {
|
|
|
|
'model_name': self.model_name,
|
|
|
|
'old_name': self.old_name,
|
|
|
|
'new_name': self.new_name,
|
|
|
|
}
|
2014-11-16 03:25:43 +08:00
|
|
|
return (
|
|
|
|
self.__class__.__name__,
|
2014-11-23 01:57:13 +08:00
|
|
|
[],
|
|
|
|
kwargs
|
2014-11-16 03:25:43 +08:00
|
|
|
)
|
|
|
|
|
2013-06-20 22:12:59 +08:00
|
|
|
def state_forwards(self, app_label, state):
|
2017-06-30 20:35:58 +08:00
|
|
|
model_state = state.models[app_label, self.model_name_lower]
|
2014-07-21 18:36:34 +08:00
|
|
|
# Rename the field
|
2017-06-30 20:35:58 +08:00
|
|
|
fields = model_state.fields
|
2020-04-22 11:14:34 +08:00
|
|
|
try:
|
|
|
|
found = fields.pop(self.old_name)
|
|
|
|
except KeyError:
|
|
|
|
raise FieldDoesNotExist(
|
|
|
|
"%s.%s has no field named '%s'" % (app_label, self.model_name, self.old_name)
|
|
|
|
)
|
|
|
|
fields[self.new_name] = found
|
|
|
|
for field in fields.values():
|
2017-11-24 16:05:56 +08:00
|
|
|
# Fix from_fields to refer to the new field.
|
|
|
|
from_fields = getattr(field, 'from_fields', None)
|
|
|
|
if from_fields:
|
|
|
|
field.from_fields = tuple([
|
|
|
|
self.new_name if from_field_name == self.old_name else from_field_name
|
|
|
|
for from_field_name in from_fields
|
|
|
|
])
|
2014-11-18 02:04:38 +08:00
|
|
|
# Fix index/unique_together to refer to the new field
|
2017-06-30 20:35:58 +08:00
|
|
|
options = model_state.options
|
2014-11-18 02:04:38 +08:00
|
|
|
for option in ('index_together', 'unique_together'):
|
|
|
|
if option in options:
|
|
|
|
options[option] = [
|
|
|
|
[self.new_name if n == self.old_name else n for n in together]
|
|
|
|
for together in options[option]
|
|
|
|
]
|
2017-11-24 16:05:56 +08:00
|
|
|
# Fix to_fields to refer to the new field.
|
2020-04-04 04:38:06 +08:00
|
|
|
delay = True
|
|
|
|
references = get_references(
|
|
|
|
state, (app_label, self.model_name_lower), (self.old_name, found),
|
|
|
|
)
|
|
|
|
for *_, field, reference in references:
|
|
|
|
delay = False
|
|
|
|
if reference.to:
|
|
|
|
remote_field, to_fields = reference.to
|
|
|
|
if getattr(remote_field, 'field_name', None) == self.old_name:
|
|
|
|
remote_field.field_name = self.new_name
|
|
|
|
if to_fields:
|
|
|
|
field.to_fields = tuple([
|
|
|
|
self.new_name if to_field_name == self.old_name else to_field_name
|
|
|
|
for to_field_name in to_fields
|
|
|
|
])
|
2016-11-06 19:03:05 +08:00
|
|
|
state.reload_model(app_label, self.model_name_lower, delay=delay)
|
2013-06-20 22:12:59 +08:00
|
|
|
|
|
|
|
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
2014-11-05 17:43:31 +08:00
|
|
|
to_model = to_state.apps.get_model(app_label, self.model_name)
|
2015-02-19 15:27:58 +08:00
|
|
|
if self.allow_migrate_model(schema_editor.connection.alias, to_model):
|
2014-11-05 17:43:31 +08:00
|
|
|
from_model = from_state.apps.get_model(app_label, self.model_name)
|
2013-07-30 19:34:31 +08:00
|
|
|
schema_editor.alter_field(
|
2013-12-11 22:19:05 +08:00
|
|
|
from_model,
|
2015-01-07 08:16:35 +08:00
|
|
|
from_model._meta.get_field(self.old_name),
|
|
|
|
to_model._meta.get_field(self.new_name),
|
2013-07-30 19:34:31 +08:00
|
|
|
)
|
2013-06-20 22:12:59 +08:00
|
|
|
|
|
|
|
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
2014-11-05 17:43:31 +08:00
|
|
|
to_model = to_state.apps.get_model(app_label, self.model_name)
|
2015-02-19 15:27:58 +08:00
|
|
|
if self.allow_migrate_model(schema_editor.connection.alias, to_model):
|
2014-11-05 17:43:31 +08:00
|
|
|
from_model = from_state.apps.get_model(app_label, self.model_name)
|
2013-07-30 19:34:31 +08:00
|
|
|
schema_editor.alter_field(
|
2013-12-11 22:19:05 +08:00
|
|
|
from_model,
|
2015-01-07 08:16:35 +08:00
|
|
|
from_model._meta.get_field(self.new_name),
|
|
|
|
to_model._meta.get_field(self.old_name),
|
2013-07-30 19:34:31 +08:00
|
|
|
)
|
2013-06-20 22:12:59 +08:00
|
|
|
|
|
|
|
def describe(self):
|
|
|
|
return "Rename field %s on %s to %s" % (self.old_name, self.model_name, self.new_name)
|
2013-11-06 21:47:58 +08:00
|
|
|
|
2020-04-04 11:05:16 +08:00
|
|
|
def references_field(self, model_name, name, app_label):
|
|
|
|
return self.references_model(model_name, app_label) and (
|
2015-01-02 23:37:21 +08:00
|
|
|
name.lower() == self.old_name_lower or
|
|
|
|
name.lower() == self.new_name_lower
|
2013-11-06 21:47:58 +08:00
|
|
|
)
|
2016-01-09 15:36:09 +08:00
|
|
|
|
2020-04-04 10:57:42 +08:00
|
|
|
def reduce(self, operation, app_label):
|
2016-01-09 15:36:09 +08:00
|
|
|
if (isinstance(operation, RenameField) and
|
|
|
|
self.is_same_model_operation(operation) and
|
|
|
|
self.new_name_lower == operation.old_name_lower):
|
|
|
|
return [
|
|
|
|
RenameField(
|
|
|
|
self.model_name,
|
|
|
|
self.old_name,
|
|
|
|
operation.new_name,
|
|
|
|
),
|
|
|
|
]
|
2016-01-09 16:12:46 +08:00
|
|
|
# Skip `FieldOperation.reduce` as we want to run `references_field`
|
|
|
|
# against self.new_name.
|
|
|
|
return (
|
2020-04-04 10:57:42 +08:00
|
|
|
super(FieldOperation, self).reduce(operation, app_label) or
|
2016-01-09 16:12:46 +08:00
|
|
|
not operation.references_field(self.model_name, self.new_name, app_label)
|
|
|
|
)
|