Opened 2 weeks ago

Last modified 12 days ago

#36564 assigned Cleanup/optimization

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: Accepted
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_FIELD from AutoField to BigAutoField.
  • 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 (3)

comment:1 by Tim Graham, 2 weeks ago

Has patch: set

comment:2 by Natalia Bidart, 2 weeks ago

Triage Stage: UnreviewedAccepted

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 Alex, 12 days ago

Cc: Alex added
Note: See TracTickets for help on using tickets.
Back to Top