From fdfb3086fcba1b737ec09676ab4bb95105f3371e Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 12 Apr 2022 15:34:26 +0200 Subject: [PATCH] Fixed DatabaseFeatures.supports_index_column_ordering and related tests with MyISAM storage engine. --- django/db/backends/mysql/features.py | 2 ++ django/db/models/indexes.py | 4 ++++ tests/indexes/tests.py | 1 + 3 files changed, 7 insertions(+) diff --git a/django/db/backends/mysql/features.py b/django/db/backends/mysql/features.py index c4706fc1b0d..a34741267ae 100644 --- a/django/db/backends/mysql/features.py +++ b/django/db/backends/mysql/features.py @@ -328,6 +328,8 @@ class DatabaseFeatures(BaseDatabaseFeatures): @cached_property def supports_index_column_ordering(self): + if self._mysql_storage_engine != "InnoDB": + return False if self.connection.mysql_is_mariadb: return self.connection.mysql_version >= (10, 8) return self.connection.mysql_version >= (8, 0, 1) diff --git a/django/db/models/indexes.py b/django/db/models/indexes.py index 3c2b699ccc0..71976c4fdde 100644 --- a/django/db/models/indexes.py +++ b/django/db/models/indexes.py @@ -111,6 +111,10 @@ class Index: for field_name, _ in self.fields_orders ] col_suffixes = [order[1] for order in self.fields_orders] + if schema_editor.connection.features.supports_index_column_ordering: + col_suffixes = [order[1] for order in self.fields_orders] + else: + col_suffixes = [""] * len(self.fields_orders) expressions = None return schema_editor._create_index_sql( model, diff --git a/tests/indexes/tests.py b/tests/indexes/tests.py index 7bc305e596d..b5cdef35453 100644 --- a/tests/indexes/tests.py +++ b/tests/indexes/tests.py @@ -93,6 +93,7 @@ class SchemaIndexesTests(TestCase): str(index.create_sql(Article, editor)), ) + @skipUnlessDBFeature("supports_index_column_ordering") def test_descending_columns_list_sql(self): index = Index(fields=["-headline"], name="whitespace_idx") editor = connection.schema_editor()