mirror of
https://github.com/django/django.git
synced 2025-12-10 19:31:35 +00:00
Fixed #36358 -- Corrected introspection of composite primary keys on SQLite.
Previously, any first field of a composite primary key with type `INTEGER` was incorrectly introspected as an `AutoField` due to SQLite treating `INTEGER PRIMARY KEY` as an alias for the `ROWID`. This change ensures that integer fields in composite PKs are not mistaken for auto-incrementing fields. Thanks Jacob Walls and Sarah Boyce for the reviews.
This commit is contained in:
parent
4c75858135
commit
07100db6f4
3 changed files with 17 additions and 11 deletions
|
|
@ -628,10 +628,7 @@ class InspectDBTransactionalTests(TransactionTestCase):
|
|||
|
||||
def test_composite_primary_key(self):
|
||||
out = StringIO()
|
||||
if connection.vendor == "sqlite":
|
||||
field_type = connection.features.introspected_field_types["AutoField"]
|
||||
else:
|
||||
field_type = connection.features.introspected_field_types["IntegerField"]
|
||||
field_type = connection.features.introspected_field_types["IntegerField"]
|
||||
call_command("inspectdb", "inspectdb_compositeprimarykeymodel", stdout=out)
|
||||
output = out.getvalue()
|
||||
self.assertIn(
|
||||
|
|
@ -639,8 +636,4 @@ class InspectDBTransactionalTests(TransactionTestCase):
|
|||
output,
|
||||
)
|
||||
self.assertIn(f"column_1 = models.{field_type}()", output)
|
||||
self.assertIn(
|
||||
"column_2 = models.%s()"
|
||||
% connection.features.introspected_field_types["IntegerField"],
|
||||
output,
|
||||
)
|
||||
self.assertIn(f"column_2 = models.{field_type}()", output)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue