Skip to content

Commit 2a63611

Browse files
timgrahamjacobtylerwalls
authored andcommitted
Fixed #36564 -- Changed DEFAULT_AUTO_FIELD from AutoField to BigAutoField.
1 parent 0ddbe12 commit 2a63611

26 files changed

Lines changed: 114 additions & 252 deletions

File tree

django/conf/app_template/apps.py-tpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ from django.apps import AppConfig
22

33

44
class {{ camel_case_app_name }}Config(AppConfig):
5-
default_auto_field = 'django.db.models.BigAutoField'
65
name = '{{ app_name }}'

django/conf/global_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def gettext_noop(s):
436436
DEFAULT_INDEX_TABLESPACE = ""
437437

438438
# Default primary key field type.
439-
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
439+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
440440

441441
# Default X-Frame-Options header value
442442
X_FRAME_OPTIONS = "DENY"

django/conf/project_template/project_name/settings.py-tpl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,3 @@ USE_TZ = True
115115
# https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/
116116

117117
STATIC_URL = 'static/'
118-
119-
# Default primary key field type
120-
# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#default-auto-field
121-
122-
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

django/db/backends/postgresql/features.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ def django_test_expected_failures(self):
123123
"test_group_by_nested_expression_with_params",
124124
}
125125
)
126+
if not is_psycopg3:
127+
expected_failures.update(
128+
{
129+
# operator does not exist: bigint[] = integer[]
130+
"postgres_tests.test_array.TestQuerying.test_gt",
131+
"postgres_tests.test_array.TestQuerying.test_in",
132+
"postgres_tests.test_array.TestQuerying.test_lt",
133+
}
134+
)
126135
return expected_failures
127136

128137
@cached_property

django/db/models/base.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,45 +1701,12 @@ def check(cls, **kwargs):
17011701
*cls._check_indexes(databases),
17021702
*cls._check_ordering(),
17031703
*cls._check_constraints(databases),
1704-
*cls._check_default_pk(),
17051704
*cls._check_db_table_comment(databases),
17061705
*cls._check_composite_pk(),
17071706
]
17081707

17091708
return errors
17101709

1711-
@classmethod
1712-
def _check_default_pk(cls):
1713-
if (
1714-
not cls._meta.abstract
1715-
and cls._meta.pk.auto_created
1716-
and
1717-
# Inherited PKs are checked in parents models.
1718-
not (
1719-
isinstance(cls._meta.pk, OneToOneField)
1720-
and cls._meta.pk.remote_field.parent_link
1721-
)
1722-
and not settings.is_overridden("DEFAULT_AUTO_FIELD")
1723-
and cls._meta.app_config
1724-
and not cls._meta.app_config._is_default_auto_field_overridden
1725-
):
1726-
return [
1727-
checks.Warning(
1728-
f"Auto-created primary key used when not defining a "
1729-
f"primary key type, by default "
1730-
f"'{settings.DEFAULT_AUTO_FIELD}'.",
1731-
hint=(
1732-
f"Configure the DEFAULT_AUTO_FIELD setting or the "
1733-
f"{cls._meta.app_config.__class__.__qualname__}."
1734-
f"default_auto_field attribute to point to a subclass "
1735-
f"of AutoField, e.g. 'django.db.models.BigAutoField'."
1736-
),
1737-
obj=cls,
1738-
id="models.W042",
1739-
),
1740-
]
1741-
return []
1742-
17431710
@classmethod
17441711
def _check_composite_pk(cls):
17451712
errors = []

docs/intro/reusable-apps.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ this. For a small app like polls, this process isn't too difficult.
153153

154154

155155
class PollsConfig(AppConfig):
156-
default_auto_field = "django.db.models.BigAutoField"
157156
name = "django_polls"
158157
label = "polls"
159158

docs/ref/checks.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ Models
429429
* **models.E042**: ``<field name>`` cannot be included in the composite
430430
primary key.
431431
* **models.W042**: Auto-created primary key used when not defining a primary
432-
key type, by default ``django.db.models.AutoField``.
432+
key type, by default ``django.db.models.AutoField``. *This check appeared in
433+
Django 3.2 - 5.2*.
433434
* **models.W043**: ``<database>`` does not support indexes on expressions.
434435
* **models.W044**: ``<database>`` does not support unique constraints on
435436
expressions.

docs/ref/settings.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,11 +1279,16 @@ See also :setting:`NUMBER_GROUPING`, :setting:`THOUSAND_SEPARATOR` and
12791279
``DEFAULT_AUTO_FIELD``
12801280
----------------------
12811281

1282-
Default: ``'``:class:`django.db.models.AutoField`\ ``'``
1282+
Default: ``'``:class:`django.db.models.BigAutoField`\ ``'``
12831283

12841284
Default primary key field type to use for models that don't have a field with
12851285
:attr:`primary_key=True <django.db.models.Field.primary_key>`.
12861286

1287+
.. versionchanged:: 6.0
1288+
1289+
In older versions, the default value is
1290+
:class:`django.db.models.AutoField`.
1291+
12871292
.. admonition:: Migrating auto-created through tables
12881293

12891294
The value of ``DEFAULT_AUTO_FIELD`` will be respected when creating new

docs/releases/6.0.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,36 @@ Email
458458
significantly, closely examine any custom subclasses that rely on overriding
459459
undocumented, internal underscore methods.
460460

461+
``DEFAULT_AUTO_FIELD`` setting now defaults to ``BigAutoField``
462+
---------------------------------------------------------------
463+
464+
Since Django 3.2 when the :setting:`DEFAULT_AUTO_FIELD` setting was added,
465+
the default :djadmin:`startproject` template's ``settings.py`` contained::
466+
467+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
468+
469+
and the default :djadmin:`startapp` template's ``AppConfig`` contained::
470+
471+
default_auto_field = "django.db.models.BigAutoField"
472+
473+
At that time, the default value of :setting:`DEFAULT_AUTO_FIELD` remained
474+
:class:`django.db.models.AutoField` for backwards compatibility.
475+
476+
In Django 6.0, :setting:`DEFAULT_AUTO_FIELD` now defaults to
477+
:class:`django.db.models.BigAutoField` and the aforementioned lines in the
478+
project and app templates are removed.
479+
480+
Most projects shouldn't be affected since there has been a system check warning
481+
since Django 3.2 if a project doesn't set :setting:`DEFAULT_AUTO_FIELD`:
482+
483+
**models.W042**: Auto-created primary key used when not defining a primary
484+
key type, by default ``django.db.models.AutoField``.
485+
486+
If you haven't dealt with this warning by now, add
487+
``DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'`` to your project's
488+
settings, or ``default_auto_field = 'django.db.models.AutoField'`` to an app's
489+
``AppConfig``, as needed.
490+
461491
Custom ORM expressions should return params as a tuple
462492
------------------------------------------------------
463493

tests/admin_scripts/tests.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def write_settings(self, filename, apps=None, is_dir=False, sdict=None, extra=No
7575
settings_file.write("%s\n" % extra)
7676
exports = [
7777
"DATABASES",
78-
"DEFAULT_AUTO_FIELD",
7978
"ROOT_URLCONF",
8079
"SECRET_KEY",
8180
"USE_TZ",
@@ -3127,11 +3126,6 @@ def test_template(self):
31273126
with open(os.path.join(app_path, "apps.py")) as f:
31283127
content = f.read()
31293128
self.assertIn("class NewAppConfig(AppConfig)", content)
3130-
if HAS_BLACK:
3131-
test_str = 'default_auto_field = "django.db.models.BigAutoField"'
3132-
else:
3133-
test_str = "default_auto_field = 'django.db.models.BigAutoField'"
3134-
self.assertIn(test_str, content)
31353129
self.assertIn(
31363130
'name = "new_app"' if HAS_BLACK else "name = 'new_app'",
31373131
content,

0 commit comments

Comments
 (0)