summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2025-04-28 22:46:13 -0400
committerNatalia <124304+nessita@users.noreply.github.com>2025-04-30 10:53:39 -0300
commit5d03c71b7a2256e776f134a7844c95f0f8f06c6d (patch)
tree68ef28f72f3f1f2d3972ef80f5cdefa38e24b55e
parent7f6a5fbe2ef26d9970508d5a7236fe009ec274d0 (diff)
[5.2.x] Refs #36052, #32234 -- Removed create_test_table_with_composite_primary_key flag in favor of using CompositePrimaryKey.
Now that Django properly supports creating models with composite primary keys, the tests should use a `CompositePrimaryKey` field instead of a feature flag to inline backend specific SQL for creating a composite PK. Specifcially, the inspectdb's test_composite_primary_key was adjusted to use schema editor instead of per-backend raw SQL. Backport of 4c75858135589f3a00e32eb4d476074536371a32 from main.
-rw-r--r--django/db/backends/base/features.py4
-rw-r--r--django/db/backends/mysql/features.py7
-rw-r--r--django/db/backends/oracle/features.py7
-rw-r--r--django/db/backends/postgresql/features.py7
-rw-r--r--django/db/backends/sqlite3/features.py7
-rw-r--r--tests/inspectdb/models.py6
-rw-r--r--tests/inspectdb/tests.py6
7 files changed, 7 insertions, 37 deletions
diff --git a/django/db/backends/base/features.py b/django/db/backends/base/features.py
index 0f8e6f41a6..de5dc12768 100644
--- a/django/db/backends/base/features.py
+++ b/django/db/backends/base/features.py
@@ -278,10 +278,6 @@ class BaseDatabaseFeatures:
create_test_procedure_without_params_sql = None
create_test_procedure_with_int_param_sql = None
- # SQL to create a table with a composite primary key for use by the Django
- # test suite.
- create_test_table_with_composite_primary_key = None
-
# Does the backend support keyword parameters for cursor.callproc()?
supports_callproc_kwargs = False
diff --git a/django/db/backends/mysql/features.py b/django/db/backends/mysql/features.py
index 414f552d94..6daf4cfbca 100644
--- a/django/db/backends/mysql/features.py
+++ b/django/db/backends/mysql/features.py
@@ -41,13 +41,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
SET V_I = P_I;
END;
"""
- create_test_table_with_composite_primary_key = """
- CREATE TABLE test_table_composite_pk (
- column_1 INTEGER NOT NULL,
- column_2 INTEGER NOT NULL,
- PRIMARY KEY(column_1, column_2)
- )
- """
# Neither MySQL nor MariaDB support partial indexes.
supports_partial_indexes = False
# COLLATE must be wrapped in parentheses because MySQL treats COLLATE as an
diff --git a/django/db/backends/oracle/features.py b/django/db/backends/oracle/features.py
index 7ebe69c6dd..20fa1673d5 100644
--- a/django/db/backends/oracle/features.py
+++ b/django/db/backends/oracle/features.py
@@ -60,13 +60,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
V_I := P_I;
END;
"""
- create_test_table_with_composite_primary_key = """
- CREATE TABLE test_table_composite_pk (
- column_1 NUMBER(11) NOT NULL,
- column_2 NUMBER(11) NOT NULL,
- PRIMARY KEY (column_1, column_2)
- )
- """
supports_callproc_kwargs = True
supports_over_clause = True
supports_frame_range_fixed_distance = True
diff --git a/django/db/backends/postgresql/features.py b/django/db/backends/postgresql/features.py
index 16653a0519..06240bdf62 100644
--- a/django/db/backends/postgresql/features.py
+++ b/django/db/backends/postgresql/features.py
@@ -52,13 +52,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
V_I := P_I;
END;
$$ LANGUAGE plpgsql;"""
- create_test_table_with_composite_primary_key = """
- CREATE TABLE test_table_composite_pk (
- column_1 INTEGER NOT NULL,
- column_2 INTEGER NOT NULL,
- PRIMARY KEY(column_1, column_2)
- )
- """
requires_casted_case_in_updates = True
supports_over_clause = True
supports_frame_exclusion = True
diff --git a/django/db/backends/sqlite3/features.py b/django/db/backends/sqlite3/features.py
index 6ab6308ece..61e6eff13d 100644
--- a/django/db/backends/sqlite3/features.py
+++ b/django/db/backends/sqlite3/features.py
@@ -51,13 +51,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
# Date/DateTime fields and timedeltas.
"expressions.tests.FTimeDeltaTests.test_mixed_comparisons1",
}
- create_test_table_with_composite_primary_key = """
- CREATE TABLE test_table_composite_pk (
- column_1 INTEGER NOT NULL,
- column_2 INTEGER NOT NULL,
- PRIMARY KEY(column_1, column_2)
- )
- """
insert_test_table_with_defaults = 'INSERT INTO {} ("null") VALUES (1)'
supports_default_keyword_in_insert = False
supports_unlimited_charfield = True
diff --git a/tests/inspectdb/models.py b/tests/inspectdb/models.py
index ad42871644..83477276c9 100644
--- a/tests/inspectdb/models.py
+++ b/tests/inspectdb/models.py
@@ -155,3 +155,9 @@ class DbComment(models.Model):
class Meta:
db_table_comment = "Custom table comment"
required_db_features = {"supports_comments"}
+
+
+class CompositePrimaryKeyModel(models.Model):
+ pk = models.CompositePrimaryKey("column_1", "column_2")
+ column_1 = models.IntegerField()
+ column_2 = models.IntegerField()
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py
index f7a6958b75..c5f4ba4c6c 100644
--- a/tests/inspectdb/tests.py
+++ b/tests/inspectdb/tests.py
@@ -626,17 +626,13 @@ class InspectDBTransactionalTests(TransactionTestCase):
self.assertIn(foreign_table_model, output)
self.assertIn(foreign_table_managed, output)
- @skipUnlessDBFeature("create_test_table_with_composite_primary_key")
def test_composite_primary_key(self):
- table_name = "test_table_composite_pk"
- cursor_execute(connection.features.create_test_table_with_composite_primary_key)
- self.addCleanup(cursor_execute, "DROP TABLE %s" % table_name)
out = StringIO()
if connection.vendor == "sqlite":
field_type = connection.features.introspected_field_types["AutoField"]
else:
field_type = connection.features.introspected_field_types["IntegerField"]
- call_command("inspectdb", table_name, stdout=out)
+ call_command("inspectdb", "inspectdb_compositeprimarykeymodel", stdout=out)
output = out.getvalue()
self.assertIn(
"pk = models.CompositePrimaryKey('column_1', 'column_2')",