Opened 3 hours ago

#35957 new New feature

Allow AutoFields in composite primary keys

Reported by: Csirmaz Bendegúz Owned by:
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is a follow up to #373 (CompositePrimaryKey), #8576 (Multiple AutoFields in a model), #27452 (SerialField).

At the moment, AutoFields must set primary_key=True.

This makes it impossible to use them with CompositePrimaryKey.

Multiple AutoFields in a model (#8576) may not be useful, but having an AutoField be part of a composite primary key has its uses. It's good practice to use surrogate keys, even if the table has a composite primary key (should this surrogate key be an auto-incremented field is another discussion).

So I think we should allow AutoFields to not set primary_key=True if they are part of a composite primary key.

Note: SQLite doesn't support AutoFields in composite primary keys.

Change History (0)

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