Opened 3 months ago
Closed 2 months ago
#36564 closed Cleanup/optimization (fixed)
Change DEFAULT_AUTO_FIELD to BigAutoField
| Reported by: | Tim Graham | Owned by: | Tim Graham |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Alex | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
In Django 3.2, the DEFAULT_AUTO_FIELD setting and AppConfig.default_auto_field attribute were added to start nudging users from AutoField to BigAutoField.
The default startproject template has DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' and the default startapp template has default_auto_field = ‘django.db.models.BigAutoField' but django.conf.global_settings has DEFAULT_AUTO_FIELD = "django.db.models.AutoField".
Phase two of the plan is changing the DEFAULT_AUTO_FIELD in django.conf.global_settings to BigAutoField. Since there has has effectively been a quasi-deprecation warning generated by the system check framework since Django 3.2 if neither DEFAULT_AUTO_FIELD nor AppConfig.default_auto_field are set, I think no deprecation period is needed and we can make these changes in Django 6.0:
- Change
django.conf.global_settings.DEFAULT_AUTO_FIELDfromAutoFieldtoBigAutoField. - Remove
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'from the default project template. - Remove
default_auto_field = 'django.db.models.BigAutoField'from the default app template. - Remove the system check that’s acted as a deprecation warning (example output below):
WARNINGS:
app_label.Model: (models.W042) 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 AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
When raised on the forum, the only concern is whether the fellows will have time to review the patch.
Change History (6)
comment:1 by , 3 months ago
| Has patch: | set |
|---|
comment:2 by , 3 months ago
| Triage Stage: | Unreviewed → Accepted |
|---|
Thank you Tim for the ticket and for starting the forum post, that's a great head start. Accepting based on the forum conversation, but as I mentioned there, we'll do our best to land this in 6.0; otherwise it will be an early 6.1 change.
comment:3 by , 3 months ago
| Cc: | added |
|---|
comment:4 by , 2 months ago
| Patch needs improvement: | set |
|---|
comment:5 by , 2 months ago
| Patch needs improvement: | unset |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
PR