Re: [Django] #36401: Adding CompositePrimaryKey to existing table leads to drop existing PK with not composite PK creation

3 views
Skip to first unread message

Django

unread,
May 19, 2025, 6:31:15 PM5/19/25
to django-...@googlegroups.com
#36401: Adding CompositePrimaryKey to existing table leads to drop existing PK with
not composite PK creation
--------------------------------+--------------------------------------
Reporter: Pavel Tyslacki | Owner: (none)
Type: New feature | Status: closed
Component: Migrations | Version: 5.2
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Jacob Walls):

* resolution: => wontfix
* status: new => closed
* type: Bug => New feature

Comment:

Hi, thanks for the report. This is
[https://docs.djangoproject.com/en/5.2/topics/composite-primary-key
/#migrating-to-a-composite-primary-key documented] as not supported:

> Django doesn’t support migrating to, or from, a composite primary key
after the table is created. It also doesn’t support adding or removing
fields from the composite primary key.
> If you would like to migrate an existing table from a single primary key
to a composite primary key, follow your database backend’s instructions to
do so.
> Once the composite primary key is in place, add the CompositePrimaryKey
field to your model. This allows Django to recognize and handle the
composite primary key appropriately.

Adding support for this would be a new feature, so setting a "wontfix"
status on this tracker with the reason that new features are currently
tracked [https://github.com/django/new-features elsewhere].
--
Ticket URL: <https://code.djangoproject.com/ticket/36401#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages