Opened 36 hours ago
Last modified 24 hours ago
#36037 new Cleanup/optimization
Documentation mentions default primary key being regular IntegerField, not BigAutoField — at Initial Version
Reported by: | Ari Pollak | Owned by: | |
---|---|---|---|
Component: | Documentation | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Currently, Django's default primary key type is a BigAutoField. However, a couple of pages still talk about it 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:
- 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”.