mirror of
https://github.com/django/django.git
synced 2025-09-10 11:09:12 +00:00
Fixed #36564 -- Changed DEFAULT_AUTO_FIELD from AutoField to BigAutoField.
This commit is contained in:
parent
0ddbe12ea9
commit
2a636118da
@ -2,5 +2,4 @@ from django.apps import AppConfig
|
|||||||
|
|
||||||
|
|
||||||
class {{ camel_case_app_name }}Config(AppConfig):
|
class {{ camel_case_app_name }}Config(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
|
||||||
name = '{{ app_name }}'
|
name = '{{ app_name }}'
|
||||||
|
@ -436,7 +436,7 @@ DEFAULT_TABLESPACE = ""
|
|||||||
DEFAULT_INDEX_TABLESPACE = ""
|
DEFAULT_INDEX_TABLESPACE = ""
|
||||||
|
|
||||||
# Default primary key field type.
|
# Default primary key field type.
|
||||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
|
|
||||||
# Default X-Frame-Options header value
|
# Default X-Frame-Options header value
|
||||||
X_FRAME_OPTIONS = "DENY"
|
X_FRAME_OPTIONS = "DENY"
|
||||||
|
@ -115,8 +115,3 @@ USE_TZ = True
|
|||||||
# https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/
|
# https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
|
|
||||||
# Default primary key field type
|
|
||||||
# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#default-auto-field
|
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
||||||
|
@ -123,6 +123,15 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||||||
"test_group_by_nested_expression_with_params",
|
"test_group_by_nested_expression_with_params",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
if not is_psycopg3:
|
||||||
|
expected_failures.update(
|
||||||
|
{
|
||||||
|
# operator does not exist: bigint[] = integer[]
|
||||||
|
"postgres_tests.test_array.TestQuerying.test_gt",
|
||||||
|
"postgres_tests.test_array.TestQuerying.test_in",
|
||||||
|
"postgres_tests.test_array.TestQuerying.test_lt",
|
||||||
|
}
|
||||||
|
)
|
||||||
return expected_failures
|
return expected_failures
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
@ -1701,45 +1701,12 @@ class Model(AltersData, metaclass=ModelBase):
|
|||||||
*cls._check_indexes(databases),
|
*cls._check_indexes(databases),
|
||||||
*cls._check_ordering(),
|
*cls._check_ordering(),
|
||||||
*cls._check_constraints(databases),
|
*cls._check_constraints(databases),
|
||||||
*cls._check_default_pk(),
|
|
||||||
*cls._check_db_table_comment(databases),
|
*cls._check_db_table_comment(databases),
|
||||||
*cls._check_composite_pk(),
|
*cls._check_composite_pk(),
|
||||||
]
|
]
|
||||||
|
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _check_default_pk(cls):
|
|
||||||
if (
|
|
||||||
not cls._meta.abstract
|
|
||||||
and cls._meta.pk.auto_created
|
|
||||||
and
|
|
||||||
# Inherited PKs are checked in parents models.
|
|
||||||
not (
|
|
||||||
isinstance(cls._meta.pk, OneToOneField)
|
|
||||||
and cls._meta.pk.remote_field.parent_link
|
|
||||||
)
|
|
||||||
and not settings.is_overridden("DEFAULT_AUTO_FIELD")
|
|
||||||
and cls._meta.app_config
|
|
||||||
and not cls._meta.app_config._is_default_auto_field_overridden
|
|
||||||
):
|
|
||||||
return [
|
|
||||||
checks.Warning(
|
|
||||||
f"Auto-created primary key used when not defining a "
|
|
||||||
f"primary key type, by default "
|
|
||||||
f"'{settings.DEFAULT_AUTO_FIELD}'.",
|
|
||||||
hint=(
|
|
||||||
f"Configure the DEFAULT_AUTO_FIELD setting or the "
|
|
||||||
f"{cls._meta.app_config.__class__.__qualname__}."
|
|
||||||
f"default_auto_field attribute to point to a subclass "
|
|
||||||
f"of AutoField, e.g. 'django.db.models.BigAutoField'."
|
|
||||||
),
|
|
||||||
obj=cls,
|
|
||||||
id="models.W042",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
return []
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _check_composite_pk(cls):
|
def _check_composite_pk(cls):
|
||||||
errors = []
|
errors = []
|
||||||
|
@ -153,7 +153,6 @@ this. For a small app like polls, this process isn't too difficult.
|
|||||||
|
|
||||||
|
|
||||||
class PollsConfig(AppConfig):
|
class PollsConfig(AppConfig):
|
||||||
default_auto_field = "django.db.models.BigAutoField"
|
|
||||||
name = "django_polls"
|
name = "django_polls"
|
||||||
label = "polls"
|
label = "polls"
|
||||||
|
|
||||||
|
@ -429,7 +429,8 @@ Models
|
|||||||
* **models.E042**: ``<field name>`` cannot be included in the composite
|
* **models.E042**: ``<field name>`` cannot be included in the composite
|
||||||
primary key.
|
primary key.
|
||||||
* **models.W042**: Auto-created primary key used when not defining a primary
|
* **models.W042**: Auto-created primary key used when not defining a primary
|
||||||
key type, by default ``django.db.models.AutoField``.
|
key type, by default ``django.db.models.AutoField``. *This check appeared in
|
||||||
|
Django 3.2 - 5.2*.
|
||||||
* **models.W043**: ``<database>`` does not support indexes on expressions.
|
* **models.W043**: ``<database>`` does not support indexes on expressions.
|
||||||
* **models.W044**: ``<database>`` does not support unique constraints on
|
* **models.W044**: ``<database>`` does not support unique constraints on
|
||||||
expressions.
|
expressions.
|
||||||
|
@ -1279,11 +1279,16 @@ See also :setting:`NUMBER_GROUPING`, :setting:`THOUSAND_SEPARATOR` and
|
|||||||
``DEFAULT_AUTO_FIELD``
|
``DEFAULT_AUTO_FIELD``
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
Default: ``'``:class:`django.db.models.AutoField`\ ``'``
|
Default: ``'``:class:`django.db.models.BigAutoField`\ ``'``
|
||||||
|
|
||||||
Default primary key field type to use for models that don't have a field with
|
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>`.
|
:attr:`primary_key=True <django.db.models.Field.primary_key>`.
|
||||||
|
|
||||||
|
.. versionchanged:: 6.0
|
||||||
|
|
||||||
|
In older versions, the default value is
|
||||||
|
:class:`django.db.models.AutoField`.
|
||||||
|
|
||||||
.. admonition:: Migrating auto-created through tables
|
.. admonition:: Migrating auto-created through tables
|
||||||
|
|
||||||
The value of ``DEFAULT_AUTO_FIELD`` will be respected when creating new
|
The value of ``DEFAULT_AUTO_FIELD`` will be respected when creating new
|
||||||
|
@ -458,6 +458,36 @@ Email
|
|||||||
significantly, closely examine any custom subclasses that rely on overriding
|
significantly, closely examine any custom subclasses that rely on overriding
|
||||||
undocumented, internal underscore methods.
|
undocumented, internal underscore methods.
|
||||||
|
|
||||||
|
``DEFAULT_AUTO_FIELD`` setting now defaults to ``BigAutoField``
|
||||||
|
---------------------------------------------------------------
|
||||||
|
|
||||||
|
Since Django 3.2 when the :setting:`DEFAULT_AUTO_FIELD` setting was added,
|
||||||
|
the default :djadmin:`startproject` template's ``settings.py`` contained::
|
||||||
|
|
||||||
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
|
|
||||||
|
and the default :djadmin:`startapp` template's ``AppConfig`` contained::
|
||||||
|
|
||||||
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
|
|
||||||
|
At that time, the default value of :setting:`DEFAULT_AUTO_FIELD` remained
|
||||||
|
:class:`django.db.models.AutoField` for backwards compatibility.
|
||||||
|
|
||||||
|
In Django 6.0, :setting:`DEFAULT_AUTO_FIELD` now defaults to
|
||||||
|
:class:`django.db.models.BigAutoField` and the aforementioned lines in the
|
||||||
|
project and app templates are removed.
|
||||||
|
|
||||||
|
Most projects shouldn't be affected since there has been a system check warning
|
||||||
|
since Django 3.2 if a project doesn't set :setting:`DEFAULT_AUTO_FIELD`:
|
||||||
|
|
||||||
|
**models.W042**: Auto-created primary key used when not defining a primary
|
||||||
|
key type, by default ``django.db.models.AutoField``.
|
||||||
|
|
||||||
|
If you haven't dealt with this warning by now, add
|
||||||
|
``DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'`` to your project's
|
||||||
|
settings, or ``default_auto_field = 'django.db.models.AutoField'`` to an app's
|
||||||
|
``AppConfig``, as needed.
|
||||||
|
|
||||||
Custom ORM expressions should return params as a tuple
|
Custom ORM expressions should return params as a tuple
|
||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ class AdminScriptTestCase(SimpleTestCase):
|
|||||||
settings_file.write("%s\n" % extra)
|
settings_file.write("%s\n" % extra)
|
||||||
exports = [
|
exports = [
|
||||||
"DATABASES",
|
"DATABASES",
|
||||||
"DEFAULT_AUTO_FIELD",
|
|
||||||
"ROOT_URLCONF",
|
"ROOT_URLCONF",
|
||||||
"SECRET_KEY",
|
"SECRET_KEY",
|
||||||
"USE_TZ",
|
"USE_TZ",
|
||||||
@ -3127,11 +3126,6 @@ class StartApp(AdminScriptTestCase):
|
|||||||
with open(os.path.join(app_path, "apps.py")) as f:
|
with open(os.path.join(app_path, "apps.py")) as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
self.assertIn("class NewAppConfig(AppConfig)", content)
|
self.assertIn("class NewAppConfig(AppConfig)", content)
|
||||||
if HAS_BLACK:
|
|
||||||
test_str = 'default_auto_field = "django.db.models.BigAutoField"'
|
|
||||||
else:
|
|
||||||
test_str = "default_auto_field = 'django.db.models.BigAutoField'"
|
|
||||||
self.assertIn(test_str, content)
|
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'name = "new_app"' if HAS_BLACK else "name = 'new_app'",
|
'name = "new_app"' if HAS_BLACK else "name = 'new_app'",
|
||||||
content,
|
content,
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
from django.apps import AppConfig
|
|
||||||
|
|
||||||
|
|
||||||
class CheckDefaultPKConfig(AppConfig):
|
|
||||||
name = "check_framework"
|
|
||||||
|
|
||||||
|
|
||||||
class CheckPKConfig(AppConfig):
|
|
||||||
name = "check_framework"
|
|
||||||
default_auto_field = "django.db.models.BigAutoField"
|
|
@ -1,5 +1,3 @@
|
|||||||
from unittest import mock
|
|
||||||
|
|
||||||
from django.core import checks
|
from django.core import checks
|
||||||
from django.core.checks import Error, Warning
|
from django.core.checks import Error, Warning
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@ -411,136 +409,3 @@ class ConstraintNameTests(TestCase):
|
|||||||
constraints = [constraint]
|
constraints = [constraint]
|
||||||
|
|
||||||
self.assertEqual(checks.run_checks(app_configs=apps.get_app_configs()), [])
|
self.assertEqual(checks.run_checks(app_configs=apps.get_app_configs()), [])
|
||||||
|
|
||||||
|
|
||||||
def mocked_is_overridden(self, setting):
|
|
||||||
# Force treating DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' as a not
|
|
||||||
# overridden setting.
|
|
||||||
return (
|
|
||||||
setting != "DEFAULT_AUTO_FIELD"
|
|
||||||
or self.DEFAULT_AUTO_FIELD != "django.db.models.AutoField"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("django.conf.UserSettingsHolder.is_overridden", mocked_is_overridden)
|
|
||||||
@override_settings(DEFAULT_AUTO_FIELD="django.db.models.AutoField")
|
|
||||||
@isolate_apps("check_framework.apps.CheckDefaultPKConfig", attr_name="apps")
|
|
||||||
@override_system_checks([checks.model_checks.check_all_models])
|
|
||||||
class ModelDefaultAutoFieldTests(SimpleTestCase):
|
|
||||||
msg = (
|
|
||||||
"Auto-created primary key used when not defining a primary key type, "
|
|
||||||
"by default 'django.db.models.AutoField'."
|
|
||||||
)
|
|
||||||
hint = (
|
|
||||||
"Configure the DEFAULT_AUTO_FIELD setting or the "
|
|
||||||
"CheckDefaultPKConfig.default_auto_field attribute to point to a "
|
|
||||||
"subclass of AutoField, e.g. 'django.db.models.BigAutoField'."
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_auto_created_pk(self):
|
|
||||||
class Model(models.Model):
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
|
||||||
[
|
|
||||||
Warning(self.msg, hint=self.hint, obj=Model, id="models.W042"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_explicit_inherited_pk(self):
|
|
||||||
class Parent(models.Model):
|
|
||||||
id = models.AutoField(primary_key=True)
|
|
||||||
|
|
||||||
class Child(Parent):
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [])
|
|
||||||
|
|
||||||
def test_skipped_on_model_with_invalid_app_label(self):
|
|
||||||
class Model(models.Model):
|
|
||||||
class Meta:
|
|
||||||
app_label = "invalid_app_label"
|
|
||||||
|
|
||||||
self.assertEqual(Model.check(), [])
|
|
||||||
|
|
||||||
def test_skipped_on_abstract_model(self):
|
|
||||||
class Abstract(models.Model):
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
# Call .check() because abstract models are not registered.
|
|
||||||
self.assertEqual(Abstract.check(), [])
|
|
||||||
|
|
||||||
def test_explicit_inherited_parent_link(self):
|
|
||||||
class Parent(models.Model):
|
|
||||||
id = models.AutoField(primary_key=True)
|
|
||||||
|
|
||||||
class Child(Parent):
|
|
||||||
parent_ptr = models.OneToOneField(Parent, models.CASCADE, parent_link=True)
|
|
||||||
|
|
||||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [])
|
|
||||||
|
|
||||||
def test_auto_created_inherited_pk(self):
|
|
||||||
class Parent(models.Model):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class Child(Parent):
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
|
||||||
[
|
|
||||||
Warning(self.msg, hint=self.hint, obj=Parent, id="models.W042"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_auto_created_inherited_parent_link(self):
|
|
||||||
class Parent(models.Model):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class Child(Parent):
|
|
||||||
parent_ptr = models.OneToOneField(Parent, models.CASCADE, parent_link=True)
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
|
||||||
[
|
|
||||||
Warning(self.msg, hint=self.hint, obj=Parent, id="models.W042"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_auto_created_pk_inherited_abstract_parent(self):
|
|
||||||
class Parent(models.Model):
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
class Child(Parent):
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
|
||||||
[
|
|
||||||
Warning(self.msg, hint=self.hint, obj=Child, id="models.W042"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
@override_settings(DEFAULT_AUTO_FIELD="django.db.models.BigAutoField")
|
|
||||||
def test_default_auto_field_setting(self):
|
|
||||||
class Model(models.Model):
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [])
|
|
||||||
|
|
||||||
def test_explicit_pk(self):
|
|
||||||
class Model(models.Model):
|
|
||||||
id = models.BigAutoField(primary_key=True)
|
|
||||||
|
|
||||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [])
|
|
||||||
|
|
||||||
@isolate_apps("check_framework.apps.CheckPKConfig", kwarg_name="apps")
|
|
||||||
def test_app_default_auto_field(self, apps):
|
|
||||||
class ModelWithPkViaAppConfig(models.Model):
|
|
||||||
class Meta:
|
|
||||||
app_label = "check_framework.apps.CheckPKConfig"
|
|
||||||
|
|
||||||
self.assertEqual(checks.run_checks(app_configs=apps.get_app_configs()), [])
|
|
||||||
|
@ -113,7 +113,7 @@ class IntrospectionTests(TransactionTestCase):
|
|||||||
[
|
[
|
||||||
connection.features.introspected_field_types[field]
|
connection.features.introspected_field_types[field]
|
||||||
for field in (
|
for field in (
|
||||||
"AutoField",
|
"BigAutoField",
|
||||||
"CharField",
|
"CharField",
|
||||||
"CharField",
|
"CharField",
|
||||||
"CharField",
|
"CharField",
|
||||||
|
@ -6,7 +6,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
"Author",
|
"Author",
|
||||||
[
|
[
|
||||||
("id", models.AutoField(primary_key=True)),
|
("id", models.BigAutoField(primary_key=True)),
|
||||||
("name", models.CharField(max_length=255)),
|
("name", models.CharField(max_length=255)),
|
||||||
("slug", models.SlugField(null=True)),
|
("slug", models.SlugField(null=True)),
|
||||||
("age", models.IntegerField(default=0)),
|
("age", models.IntegerField(default=0)),
|
||||||
@ -16,7 +16,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
"Tribble",
|
"Tribble",
|
||||||
[
|
[
|
||||||
("id", models.AutoField(primary_key=True)),
|
("id", models.BigAutoField(primary_key=True)),
|
||||||
("fluffy", models.BooleanField(default=True)),
|
("fluffy", models.BooleanField(default=True)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -13,7 +13,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
"Book",
|
"Book",
|
||||||
[
|
[
|
||||||
("id", models.AutoField(primary_key=True)),
|
("id", models.BigAutoField(primary_key=True)),
|
||||||
(
|
(
|
||||||
"author",
|
"author",
|
||||||
models.ForeignKey("migrations.Author", models.SET_NULL, null=True),
|
models.ForeignKey("migrations.Author", models.SET_NULL, null=True),
|
||||||
|
@ -12,7 +12,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -28,7 +28,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
|
@ -10,7 +10,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
|
@ -443,30 +443,30 @@ class AbstractInheritanceTests(SimpleTestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
fields(model1),
|
fields(model1),
|
||||||
[
|
[
|
||||||
("id", models.AutoField),
|
("id", models.BigAutoField),
|
||||||
("name", models.CharField),
|
("name", models.CharField),
|
||||||
("age", models.IntegerField),
|
("age", models.IntegerField),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
fields(model2), [("id", models.AutoField), ("name", models.CharField)]
|
fields(model2), [("id", models.BigAutoField), ("name", models.CharField)]
|
||||||
)
|
)
|
||||||
self.assertEqual(getattr(model2, "age"), 2)
|
self.assertEqual(getattr(model2, "age"), 2)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
fields(model3), [("id", models.AutoField), ("name", models.CharField)]
|
fields(model3), [("id", models.BigAutoField), ("name", models.CharField)]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
fields(model4), [("id", models.AutoField), ("name", models.CharField)]
|
fields(model4), [("id", models.BigAutoField), ("name", models.CharField)]
|
||||||
)
|
)
|
||||||
self.assertEqual(getattr(model4, "age"), 2)
|
self.assertEqual(getattr(model4, "age"), 2)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
fields(model5),
|
fields(model5),
|
||||||
[
|
[
|
||||||
("id", models.AutoField),
|
("id", models.BigAutoField),
|
||||||
("foo", models.IntegerField),
|
("foo", models.IntegerField),
|
||||||
("concretemodel_ptr", models.OneToOneField),
|
("concretemodel_ptr", models.OneToOneField),
|
||||||
("age", models.SmallIntegerField),
|
("age", models.SmallIntegerField),
|
||||||
|
@ -10,6 +10,14 @@ class MyBigAutoField(models.BigAutoField):
|
|||||||
|
|
||||||
@isolate_apps("model_options")
|
@isolate_apps("model_options")
|
||||||
class TestDefaultPK(SimpleTestCase):
|
class TestDefaultPK(SimpleTestCase):
|
||||||
|
def test_default_value_of_default_auto_field_setting(self):
|
||||||
|
"""django.conf.global_settings defaults to BigAutoField."""
|
||||||
|
|
||||||
|
class MyModel(models.Model):
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.assertIsInstance(MyModel._meta.pk, models.BigAutoField)
|
||||||
|
|
||||||
@override_settings(DEFAULT_AUTO_FIELD="django.db.models.NonexistentAutoField")
|
@override_settings(DEFAULT_AUTO_FIELD="django.db.models.NonexistentAutoField")
|
||||||
def test_default_auto_field_setting_nonexistent(self):
|
def test_default_auto_field_setting_nonexistent(self):
|
||||||
msg = (
|
msg = (
|
||||||
|
@ -11,7 +11,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
|
@ -11,7 +11,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
|
@ -25,7 +25,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -44,7 +44,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -65,7 +65,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -85,7 +85,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -125,7 +125,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -134,7 +134,7 @@ class Migration(migrations.Migration):
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
"field",
|
"field",
|
||||||
ArrayField(models.IntegerField(), blank=True, default=list),
|
ArrayField(models.BigIntegerField(), blank=True, default=list),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
@ -147,7 +147,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -169,7 +169,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -191,7 +191,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -200,11 +200,13 @@ class Migration(migrations.Migration):
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
"field",
|
"field",
|
||||||
ArrayField(models.IntegerField(), null=True, blank=True),
|
ArrayField(models.BigIntegerField(), null=True, blank=True),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"field_nested",
|
"field_nested",
|
||||||
ArrayField(ArrayField(models.IntegerField(null=True)), null=True),
|
ArrayField(
|
||||||
|
ArrayField(models.BigIntegerField(null=True)), null=True
|
||||||
|
),
|
||||||
),
|
),
|
||||||
("order", models.IntegerField(null=True)),
|
("order", models.IntegerField(null=True)),
|
||||||
],
|
],
|
||||||
@ -218,7 +220,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -235,7 +237,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -272,7 +274,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -290,7 +292,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -307,7 +309,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -341,7 +343,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -363,7 +365,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -385,7 +387,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -412,7 +414,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -427,7 +429,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -442,7 +444,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -469,7 +471,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -508,7 +510,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -530,7 +532,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
@ -545,7 +547,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"id",
|
"id",
|
||||||
models.AutoField(
|
models.BigAutoField(
|
||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
serialize=False,
|
serialize=False,
|
||||||
auto_created=True,
|
auto_created=True,
|
||||||
|
@ -45,12 +45,12 @@ class PostgreSQLModel(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class IntegerArrayModel(PostgreSQLModel):
|
class IntegerArrayModel(PostgreSQLModel):
|
||||||
field = ArrayField(models.IntegerField(), default=list, blank=True)
|
field = ArrayField(models.BigIntegerField(), default=list, blank=True)
|
||||||
|
|
||||||
|
|
||||||
class NullableIntegerArrayModel(PostgreSQLModel):
|
class NullableIntegerArrayModel(PostgreSQLModel):
|
||||||
field = ArrayField(models.IntegerField(), blank=True, null=True)
|
field = ArrayField(models.BigIntegerField(), blank=True, null=True)
|
||||||
field_nested = ArrayField(ArrayField(models.IntegerField(null=True)), null=True)
|
field_nested = ArrayField(ArrayField(models.BigIntegerField(null=True)), null=True)
|
||||||
order = models.IntegerField(null=True)
|
order = models.IntegerField(null=True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -821,7 +821,7 @@ class ExclusionConstraintTests(PostgreSQLTestCase):
|
|||||||
OpClass(TsTzRange("start", "end", RangeBoundary()), "range_ops"),
|
OpClass(TsTzRange("start", "end", RangeBoundary()), "range_ops"),
|
||||||
RangeOperators.OVERLAPS,
|
RangeOperators.OVERLAPS,
|
||||||
),
|
),
|
||||||
(OpClass("room", "gist_int4_ops"), RangeOperators.EQUAL),
|
(OpClass("room", "gist_int8_ops"), RangeOperators.EQUAL),
|
||||||
],
|
],
|
||||||
condition=Q(cancelled=False),
|
condition=Q(cancelled=False),
|
||||||
)
|
)
|
||||||
|
@ -1697,7 +1697,7 @@ class SchemaTests(TransactionTestCase):
|
|||||||
columns = self.column_classes(Book)
|
columns = self.column_classes(Book)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
columns["author_id"][0],
|
columns["author_id"][0],
|
||||||
connection.features.introspected_field_types["IntegerField"],
|
connection.features.introspected_field_types["BigIntegerField"],
|
||||||
)
|
)
|
||||||
self.assertForeignKeyExists(Book, "author_id", "schema_author")
|
self.assertForeignKeyExists(Book, "author_id", "schema_author")
|
||||||
# Alter the FK
|
# Alter the FK
|
||||||
@ -1709,7 +1709,7 @@ class SchemaTests(TransactionTestCase):
|
|||||||
columns = self.column_classes(Book)
|
columns = self.column_classes(Book)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
columns["author_id"][0],
|
columns["author_id"][0],
|
||||||
connection.features.introspected_field_types["IntegerField"],
|
connection.features.introspected_field_types["BigIntegerField"],
|
||||||
)
|
)
|
||||||
self.assertForeignKeyExists(Book, "author_id", "schema_author")
|
self.assertForeignKeyExists(Book, "author_id", "schema_author")
|
||||||
|
|
||||||
@ -1761,7 +1761,7 @@ class SchemaTests(TransactionTestCase):
|
|||||||
columns = self.column_classes(BookWithO2O)
|
columns = self.column_classes(BookWithO2O)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
columns["author_id"][0],
|
columns["author_id"][0],
|
||||||
connection.features.introspected_field_types["IntegerField"],
|
connection.features.introspected_field_types["BigIntegerField"],
|
||||||
)
|
)
|
||||||
# Ensure the field is unique
|
# Ensure the field is unique
|
||||||
author = Author.objects.create(name="Joe")
|
author = Author.objects.create(name="Joe")
|
||||||
@ -1783,7 +1783,7 @@ class SchemaTests(TransactionTestCase):
|
|||||||
columns = self.column_classes(Book)
|
columns = self.column_classes(Book)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
columns["author_id"][0],
|
columns["author_id"][0],
|
||||||
connection.features.introspected_field_types["IntegerField"],
|
connection.features.introspected_field_types["BigIntegerField"],
|
||||||
)
|
)
|
||||||
# Ensure the field is not unique anymore
|
# Ensure the field is not unique anymore
|
||||||
Book.objects.create(
|
Book.objects.create(
|
||||||
@ -1807,7 +1807,7 @@ class SchemaTests(TransactionTestCase):
|
|||||||
columns = self.column_classes(Book)
|
columns = self.column_classes(Book)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
columns["author_id"][0],
|
columns["author_id"][0],
|
||||||
connection.features.introspected_field_types["IntegerField"],
|
connection.features.introspected_field_types["BigIntegerField"],
|
||||||
)
|
)
|
||||||
# Ensure the field is not unique
|
# Ensure the field is not unique
|
||||||
author = Author.objects.create(name="Joe")
|
author = Author.objects.create(name="Joe")
|
||||||
@ -1828,7 +1828,7 @@ class SchemaTests(TransactionTestCase):
|
|||||||
columns = self.column_classes(BookWithO2O)
|
columns = self.column_classes(BookWithO2O)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
columns["author_id"][0],
|
columns["author_id"][0],
|
||||||
connection.features.introspected_field_types["IntegerField"],
|
connection.features.introspected_field_types["BigIntegerField"],
|
||||||
)
|
)
|
||||||
# Ensure the field is unique now
|
# Ensure the field is unique now
|
||||||
BookWithO2O.objects.create(
|
BookWithO2O.objects.create(
|
||||||
@ -1901,7 +1901,7 @@ class SchemaTests(TransactionTestCase):
|
|||||||
columns = self.column_classes(Author)
|
columns = self.column_classes(Author)
|
||||||
field_type, _ = columns["note_ptr_id"]
|
field_type, _ = columns["note_ptr_id"]
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
field_type, connection.features.introspected_field_types["IntegerField"]
|
field_type, connection.features.introspected_field_types["BigIntegerField"]
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_alter_field_fk_keeps_index(self):
|
def test_alter_field_fk_keeps_index(self):
|
||||||
@ -2506,7 +2506,7 @@ class SchemaTests(TransactionTestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
columns["tagm2mtest_id"][0],
|
columns["tagm2mtest_id"][0],
|
||||||
connection.features.introspected_field_types["IntegerField"],
|
connection.features.introspected_field_types["BigIntegerField"],
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_m2m_create(self):
|
def test_m2m_create(self):
|
||||||
@ -2551,11 +2551,11 @@ class SchemaTests(TransactionTestCase):
|
|||||||
columns = self.column_classes(LocalTagThrough)
|
columns = self.column_classes(LocalTagThrough)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
columns["book_id"][0],
|
columns["book_id"][0],
|
||||||
connection.features.introspected_field_types["IntegerField"],
|
connection.features.introspected_field_types["BigIntegerField"],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
columns["tag_id"][0],
|
columns["tag_id"][0],
|
||||||
connection.features.introspected_field_types["IntegerField"],
|
connection.features.introspected_field_types["BigIntegerField"],
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_m2m_create_through(self):
|
def test_m2m_create_through(self):
|
||||||
@ -2651,7 +2651,7 @@ class SchemaTests(TransactionTestCase):
|
|||||||
columns = self.column_classes(new_field.remote_field.through)
|
columns = self.column_classes(new_field.remote_field.through)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
columns["tagm2mtest_id"][0],
|
columns["tagm2mtest_id"][0],
|
||||||
connection.features.introspected_field_types["IntegerField"],
|
connection.features.introspected_field_types["BigIntegerField"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# "Alter" the field. This should not rename the DB table to itself.
|
# "Alter" the field. This should not rename the DB table to itself.
|
||||||
@ -4537,7 +4537,7 @@ class SchemaTests(TransactionTestCase):
|
|||||||
letters.
|
letters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_field(*args, field_class=IntegerField, **kwargs):
|
def get_field(*args, field_class=BigIntegerField, **kwargs):
|
||||||
kwargs["db_column"] = "CamelCase"
|
kwargs["db_column"] = "CamelCase"
|
||||||
field = field_class(*args, **kwargs)
|
field = field_class(*args, **kwargs)
|
||||||
field.set_attributes_from_name("CamelCase")
|
field.set_attributes_from_name("CamelCase")
|
||||||
|
@ -28,6 +28,4 @@ PASSWORD_HASHERS = [
|
|||||||
"django.contrib.auth.hashers.MD5PasswordHasher",
|
"django.contrib.auth.hashers.MD5PasswordHasher",
|
||||||
]
|
]
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
|
||||||
|
|
||||||
USE_TZ = False
|
USE_TZ = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user