From b5e12d490af3debca8c55ab3c1698189fdedbbdb Mon Sep 17 00:00:00 2001 From: Tom Forbes Date: Sun, 12 Jul 2020 13:59:57 +0100 Subject: Fixed #31007 -- Allowed specifying type of auto-created primary keys. This also changes the default type of auto-created primary keys for new apps and projects to BigAutoField. --- docs/topics/db/models.txt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'docs/topics') diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt index 81eb5b516b..26a6d7dc58 100644 --- a/docs/topics/db/models.txt +++ b/docs/topics/db/models.txt @@ -259,11 +259,12 @@ details can be found in the :ref:`common model field option reference Automatic primary key fields ---------------------------- -By default, Django gives each model the following field:: +By default, Django gives each model an auto-incrementing primary key with the +type specified per app in :attr:`AppConfig.default_auto_field +` or globally in the +:setting:`DEFAULT_AUTO_FIELD` setting. For example:: - id = models.AutoField(primary_key=True) - -This is an auto-incrementing primary key. + id = models.BigAutoField(primary_key=True) If you'd like to specify a custom primary key, specify :attr:`primary_key=True ` on one of your fields. If Django @@ -273,6 +274,11 @@ sees you've explicitly set :attr:`Field.primary_key`, it won't add the automatic Each model requires exactly one field to have :attr:`primary_key=True ` (either explicitly declared or automatically added). +.. versionchanged:: 3.2 + + In older versions, auto-created primary key fields were always + :class:`AutoField`\s. + .. _verbose-field-names: Verbose field names -- cgit v1.3