summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorTom Forbes <tom@tomforb.es>2020-07-12 13:59:57 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-12-15 11:25:46 +0100
commitb5e12d490af3debca8c55ab3c1698189fdedbbdb (patch)
tree5fe3005ac567f3addf78b81ae033191e2fa642f4 /docs/ref
parentb960e4ed722a04a9db0d35293f76e253eedf9126 (diff)
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.
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/applications.txt11
-rw-r--r--docs/ref/checks.txt2
-rw-r--r--docs/ref/models/fields.txt14
-rw-r--r--docs/ref/settings.txt11
4 files changed, 35 insertions, 3 deletions
diff --git a/docs/ref/applications.txt b/docs/ref/applications.txt
index 765e9e8d3c..2cf175e9f0 100644
--- a/docs/ref/applications.txt
+++ b/docs/ref/applications.txt
@@ -90,6 +90,7 @@ would provide a proper name for the admin::
from django.apps import AppConfig
class RockNRollConfig(AppConfig):
+ default_auto_field = 'django.db.models.BigAutoField'
name = 'rock_n_roll'
verbose_name = "Rock ’n’ roll"
@@ -219,6 +220,16 @@ Configurable attributes
By default, this attribute isn't set.
+.. attribute:: AppConfig.default_auto_field
+
+ .. versionadded:: 3.2
+
+ The implicit primary key type to add to models within this app. You can
+ use this to keep :class:`~django.db.models.AutoField` as the primary key
+ type for third party applications.
+
+ By default, this is the value of :setting:`DEFAULT_AUTO_FIELD`.
+
Read-only attributes
--------------------
diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt
index 2ac5d4cb1d..a6e66d462f 100644
--- a/docs/ref/checks.txt
+++ b/docs/ref/checks.txt
@@ -378,6 +378,8 @@ Models
* **models.W040**: ``<database>`` does not support indexes with non-key
columns.
* **models.E041**: ``constraints`` refers to the joined field ``<field name>``.
+* **models.W042**: Auto-created primary key used when not defining a primary
+ key type, by default ``django.db.models.AutoField``.
Security
--------
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index 93c011fe2c..759e004fcf 100644
--- a/docs/ref/models/fields.txt
+++ b/docs/ref/models/fields.txt
@@ -415,9 +415,12 @@ cross-site scripting attack.
If ``True``, this field is the primary key for the model.
If you don't specify ``primary_key=True`` for any field in your model, Django
-will automatically add an :class:`AutoField` 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
+will automatically add a field 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. The type of auto-created primary key fields can
+be specified per app in :attr:`AppConfig.default_auto_field
+<django.apps.AppConfig.default_auto_field>` or globally in the
+:setting:`DEFAULT_AUTO_FIELD` setting. For more, see
:ref:`automatic-primary-key-fields`.
``primary_key=True`` implies :attr:`null=False <Field.null>` and
@@ -428,6 +431,11 @@ The primary key field is read-only. If you change the value of the primary
key on an existing object and then save it, a new object will be created
alongside the old one.
+.. versionchanged:: 3.2
+
+ In older versions, auto-created primary key fields were always
+ :class:`AutoField`\s.
+
``unique``
----------
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
index bfa62f1508..8cb14e9768 100644
--- a/docs/ref/settings.txt
+++ b/docs/ref/settings.txt
@@ -1245,6 +1245,17 @@ format has higher precedence and will be applied instead.
See also :setting:`NUMBER_GROUPING`, :setting:`THOUSAND_SEPARATOR` and
:setting:`USE_THOUSAND_SEPARATOR`.
+.. setting:: DEFAULT_AUTO_FIELD
+
+``DEFAULT_AUTO_FIELD``
+----------------------
+
+.. versionadded:: 3.2
+
+Default: ``'``:class:`django.db.models.AutoField`\ ``'``
+
+Default primary key field type to use for models that don't have a field with
+:attr:`primary_key=True <django.db.models.Field.primary_key>`.
.. setting:: DEFAULT_CHARSET