mirror of
https://github.com/django/django.git
synced 2025-05-14 10:56:29 +00:00
[5.2.x] Fixed #36357 -- Skipped unique_together in inspectdb output for composite primary keys.
Thanks to Baptiste Mispelon for the report and quick fix, and to Simon Charette and Jacob Walls for the reviews. Co-authored-by: Natalia <124304+nessita@users.noreply.github.com> Backport of 66f9eb0ff1e7147406318c5ba609729678e4e6f6 from main.
This commit is contained in:
parent
ec73fd6746
commit
1367a197dd
@ -391,7 +391,7 @@ class Command(BaseCommand):
|
||||
columns = [
|
||||
x for x in columns if x is not None and x in column_to_field_name
|
||||
]
|
||||
if len(columns) > 1:
|
||||
if len(columns) > 1 and not params["primary_key"]:
|
||||
unique_together.append(
|
||||
str(tuple(column_to_field_name[c] for c in columns))
|
||||
)
|
||||
|
@ -59,3 +59,7 @@ Bugfixes
|
||||
* Fixed a bug in composite primary key introspection that caused
|
||||
``IntegerField`` to be wrongly identified as ``AutoField`` on SQLite
|
||||
(:ticket:`36358`).
|
||||
|
||||
* Fixed a bug in Django 5.2 that caused a redundant ``unique_together``
|
||||
constraint to be generated for composite primary keys when using
|
||||
:djadmin:`inspectdb` (:ticket:`36357`).
|
||||
|
@ -637,3 +637,8 @@ class InspectDBTransactionalTests(TransactionTestCase):
|
||||
)
|
||||
self.assertIn(f"column_1 = models.{field_type}()", output)
|
||||
self.assertIn(f"column_2 = models.{field_type}()", output)
|
||||
|
||||
def test_composite_primary_key_not_unique_together(self):
|
||||
out = StringIO()
|
||||
call_command("inspectdb", "inspectdb_compositeprimarykeymodel", stdout=out)
|
||||
self.assertNotIn("unique_together", out.getvalue())
|
||||
|
Loading…
x
Reference in New Issue
Block a user