Opened 9 days ago

Closed 30 hours ago

#35992 closed Bug (fixed)

Migrations crash on constraints/indexes with CompositePrimaryKey.

Reported by: Mariusz Felisiak Owned by: Mariusz Felisiak
Component: Database layer (models, ORM) Version: dev
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've created a sample project that tries to add UniqueConstraint with a CompositePrimaryKey. Unfortunately, it crashes with programming error because CompositePrimaryKey is resolved to tuple, e.g.

CREATE UNIQUE INDEX "uq_mix" ON "test373composite_release" (("version", "name"));
  File "/ticket_373_uq_composite/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
django.db.utils.ProgrammingError: syntax error at or near ","
LINE 1: ..."uq_mix" ON "test373composite_release" (("version", "name"))
                                                             ^

I've attached a sample project. I can prepare a patch in the coming days.

Attachments (1)

ticket_373_uq_composite.zip (7.5 KB ) - added by Mariusz Felisiak 9 days ago.

Download all attachments as: .zip

Change History (6)

by Mariusz Felisiak, 9 days ago

Attachment: ticket_373_uq_composite.zip added

comment:1 by Sarah Boyce, 8 days ago

Triage Stage: UnreviewedAccepted

Thank you for testing!

comment:2 by Mariusz Felisiak, 8 days ago

Has patch: set

comment:3 by Mariusz Felisiak, 7 days ago

Alternative PR.

comment:4 by Sarah Boyce, 30 hours ago

Triage Stage: AcceptedReady for checkin

comment:5 by Sarah Boyce <42296566+sarahboyce@…>, 30 hours ago

Resolution: fixed
Status: assignedclosed

In 2249370c:

Fixed #35992, Fixed #35997 -- Added system check for CompositePrimaryKeys in Meta.indexes/constraints/unique_together.

CompositePrimaryKeys are not supported in any of these options.

Note: See TracTickets for help on using tickets.
Back to Top