diff options
| author | Simon Charette <charette.s@gmail.com> | 2025-04-28 22:46:13 -0400 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2025-04-30 10:53:39 -0300 |
| commit | 5d03c71b7a2256e776f134a7844c95f0f8f06c6d (patch) | |
| tree | 68ef28f72f3f1f2d3972ef80f5cdefa38e24b55e /tests | |
| parent | 7f6a5fbe2ef26d9970508d5a7236fe009ec274d0 (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.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/inspectdb/models.py | 6 | ||||
| -rw-r--r-- | tests/inspectdb/tests.py | 6 |
2 files changed, 7 insertions, 5 deletions
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')", |
