From a6385b382e05a614a99e5a5913d8e631823159a2 Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Tue, 17 May 2022 16:13:35 +0200 Subject: Fixed #27236 -- Deprecated Meta.index_together in favor of Meta.indexes. This also deprecates AlterIndexTogether migration operation. --- .../migrations_test_apps/__init__.py | 0 .../index_together_app/__init__.py | 0 .../migrations_test_apps/index_together_app/apps.py | 5 +++++ .../index_together_app/migrations/0001_initial.py | 16 ++++++++++++++++ .../index_together_app/migrations/__init__.py | 0 tests/check_framework/test_migrations.py | 21 +++++++++++++++++++++ 6 files changed, 42 insertions(+) create mode 100644 tests/check_framework/migrations_test_apps/__init__.py create mode 100644 tests/check_framework/migrations_test_apps/index_together_app/__init__.py create mode 100644 tests/check_framework/migrations_test_apps/index_together_app/apps.py create mode 100644 tests/check_framework/migrations_test_apps/index_together_app/migrations/0001_initial.py create mode 100644 tests/check_framework/migrations_test_apps/index_together_app/migrations/__init__.py (limited to 'tests/check_framework') diff --git a/tests/check_framework/migrations_test_apps/__init__.py b/tests/check_framework/migrations_test_apps/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/check_framework/migrations_test_apps/index_together_app/__init__.py b/tests/check_framework/migrations_test_apps/index_together_app/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/check_framework/migrations_test_apps/index_together_app/apps.py b/tests/check_framework/migrations_test_apps/index_together_app/apps.py new file mode 100644 index 0000000000..3bb7170897 --- /dev/null +++ b/tests/check_framework/migrations_test_apps/index_together_app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class IndexTogetherAppConfig(AppConfig): + name = "check_framework.migrations_test_apps.index_together_app" diff --git a/tests/check_framework/migrations_test_apps/index_together_app/migrations/0001_initial.py b/tests/check_framework/migrations_test_apps/index_together_app/migrations/0001_initial.py new file mode 100644 index 0000000000..c642ee6c57 --- /dev/null +++ b/tests/check_framework/migrations_test_apps/index_together_app/migrations/0001_initial.py @@ -0,0 +1,16 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + operations = [ + migrations.CreateModel( + "SimpleModel", + [ + ("field", models.IntegerField()), + ], + ), + migrations.AlterIndexTogether("SimpleModel", index_together=(("id", "field"),)), + ] diff --git a/tests/check_framework/migrations_test_apps/index_together_app/migrations/__init__.py b/tests/check_framework/migrations_test_apps/index_together_app/migrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/check_framework/test_migrations.py b/tests/check_framework/test_migrations.py index 0b00690e77..e41a68fa54 100644 --- a/tests/check_framework/test_migrations.py +++ b/tests/check_framework/test_migrations.py @@ -1,7 +1,11 @@ +from unittest.mock import ANY + from django.core import checks +from django.core.checks.migrations import check_migration_operations from django.db import migrations from django.db.migrations.operations.base import Operation from django.test import TestCase +from django.test.utils import override_settings class DeprecatedMigrationOperationTests(TestCase): @@ -50,6 +54,23 @@ class DeprecatedMigrationOperationTests(TestCase): ], ) + @override_settings( + INSTALLED_APPS=["check_framework.migrations_test_apps.index_together_app"] + ) + def tests_check_alter_index_together(self): + errors = check_migration_operations() + self.assertEqual( + errors, + [ + checks.Warning( + "AlterIndexTogether is deprecated. Support for it (except in " + "historical migrations) will be removed in Django 5.1.", + obj=ANY, + id="migrations.W001", + ) + ], + ) + class RemovedMigrationOperationTests(TestCase): def test_default_operation(self): -- cgit v1.2.1