Opened 6 weeks ago

Closed 5 weeks ago

#36037 closed Cleanup/optimization (fixed)

Documentation mentions default primary key being regular IntegerField, not BigAutoField

Reported by: Ari Pollak Owned by: Ari Pollak
Component: Documentation Version: 5.1
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Ari Pollak)

BigAutoField is the default type of primary key now, and in Postgres, regular IntegerField only goes up to around 2 billion. However, a couple of pages still talk about the default primary key being an IntegerField.

Under https://docs.djangoproject.com/en/5.1/topics/db/models/#field-options:

If you don’t specify primary_key=True for any fields in your model, Django will automatically add an IntegerField to hold the primary key, so you don’t need to set primary_key=True on any of your fields unless you want to override the default primary-key behavior. For more, see Automatic primary key fields

Under https://docs.djangoproject.com/en/5.1/ref/contrib/contenttypes/#generic-relations:

  1. Give your model a field that can store primary key values from the models you’ll be relating to. For most models, this means a PositiveIntegerField. The usual name for this field is “object_id”.

Change History (7)

comment:1 by Ari Pollak, 6 weeks ago

Description: modified (diff)

comment:3 by dimen61, 6 weeks ago

Hi, Ari. Since you are working with this issue, please update the tag "Owned by" to youself.

comment:4 by JaeHyuckSa, 6 weeks ago

Owner: set to Ari Pollak
Status: newassigned

comment:5 by Tim Graham, 6 weeks ago

Triage Stage: UnreviewedAccepted

comment:6 by Sarah Boyce, 5 weeks ago

Triage Stage: AcceptedReady for checkin

comment:7 by Sarah Boyce <42296566+sarahboyce@…>, 5 weeks ago

Resolution: fixed
Status: assignedclosed

In ad385ae:

Fixed #36037 -- Fixed default primary key type in docs.

BigAutoField is the default type for primary keys. In models.txt, the linked
anchor shows that the default primary key is a BigAutoField, so it now defers
to that section instead of duplicating an (incorrect) type.

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