diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index 4bcbae8bd38..ad324376307 100644 --- a/django/db/migrations/autodetector.py +++ b/django/db/migrations/autodetector.py @@ -189,14 +189,14 @@ class MigrationAutodetector: self.generate_renamed_indexes() # Generate removal of foo together. self.generate_removed_altered_unique_together() - self.generate_removed_altered_index_together() + self.generate_removed_altered_index_together() # RemovedInDjango51Warning. # Generate field operations. self.generate_removed_fields() self.generate_added_fields() self.generate_altered_fields() self.generate_altered_order_with_respect_to() self.generate_altered_unique_together() - self.generate_altered_index_together() + self.generate_altered_index_together() # RemovedInDjango51Warning. self.generate_added_indexes() self.generate_added_constraints() self.generate_altered_db_table() @@ -616,6 +616,7 @@ class MigrationAutodetector: indexes = model_state.options.pop("indexes") constraints = model_state.options.pop("constraints") unique_together = model_state.options.pop("unique_together", None) + # RemovedInDjango51Warning. index_together = model_state.options.pop("index_together", None) order_with_respect_to = model_state.options.pop( "order_with_respect_to", None @@ -745,6 +746,7 @@ class MigrationAutodetector: ), dependencies=related_dependencies, ) + # RemovedInDjango51Warning. if index_together: self.add_operation( app_label, @@ -834,6 +836,7 @@ class MigrationAutodetector: related_fields[field_name] = field # Generate option removal first unique_together = model_state.options.pop("unique_together", None) + # RemovedInDjango51Warning. index_together = model_state.options.pop("index_together", None) if unique_together: self.add_operation( @@ -843,6 +846,7 @@ class MigrationAutodetector: unique_together=None, ), ) + # RemovedInDjango51Warning. if index_together: self.add_operation( app_label, @@ -1500,6 +1504,7 @@ class MigrationAutodetector: def generate_removed_altered_unique_together(self): self._generate_removed_altered_foo_together(operations.AlterUniqueTogether) + # RemovedInDjango51Warning. def generate_removed_altered_index_together(self): self._generate_removed_altered_foo_together(operations.AlterIndexTogether) @@ -1522,6 +1527,7 @@ class MigrationAutodetector: def generate_altered_unique_together(self): self._generate_altered_foo_together(operations.AlterUniqueTogether) + # RemovedInDjango51Warning. def generate_altered_index_together(self): self._generate_altered_foo_together(operations.AlterIndexTogether) diff --git a/django/db/models/base.py b/django/db/models/base.py index 69224c02870..04f045d9238 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -1841,6 +1841,7 @@ class Model(metaclass=ModelBase): ) return errors + # RemovedInDjango51Warning. @classmethod def _check_index_together(cls): """Check the value of "index_together" option.""" diff --git a/django/db/models/options.py b/django/db/models/options.py index 938b996d67b..bff55011dc8 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -42,6 +42,7 @@ DEFAULT_NAMES = ( "proxy", "swappable", "auto_created", + # Must be kept for backward compatibility with old migrations. "index_together", "apps", "default_permissions", @@ -115,7 +116,7 @@ class Options: self.indexes = [] self.constraints = [] self.unique_together = [] - self.index_together = [] + self.index_together = [] # RemovedInDjango51Warning. self.select_on_save = False self.default_permissions = ("add", "change", "delete", "view") self.permissions = [] diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index d60f5cd1833..8c7edac4782 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -2491,7 +2491,6 @@ class OperationTests(OperationTestBase): atomic=connection.features.supports_atomic_references_rename, ) - @ignore_warnings(category=RemovedInDjango51Warning) def test_rename_field(self): """ Tests the RenameField operation.