Reproduction:
* in a new virtualenv, `pip install django==3.2.2`
* generate a new template project `django-admin startproject mysite .`
* confirm the generated `settings.py` doesn't mention
DEFAULT_AUTO_FIELD
* run though the tutorial, up to and including
https://docs.djangoproject.com/en/3.2/intro/tutorial02/#creating-models
* attempt to `python manage.py makemigrations polls`
* get errors
{{{
System check identified some issues:
WARNINGS:
polls.Choice: (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
PollsConfig.default_auto_field attribute to point to a subclass of
AutoField, e.g. 'django.db.models.BigAutoField'.
polls.Question: (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
PollsConfig.default_auto_field attribute to point to a subclass of
AutoField, e.g. 'django.db.models.BigAutoField'.
Migrations for 'polls':
polls/migrations/0001_initial.py
- Create model Question
- Create model Choice
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32741>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Katie McLaughlin):
There are two ways that this could be solved:
* Adjusting the template `settings.py` to add `DEFAULT_AUTO_FIELD =
'django.db.models.AutoField'`
* Adjusting the tutorial models to include `id =
models.AutoField(primary_key=True)` for each model.
I want to say the tutorial model update is better because it means not
touching the template project, but I'm also not sure how important this
default is with respect to having the default at start for new projects.
--
Ticket URL: <https://code.djangoproject.com/ticket/32741#comment:1>
* status: new => closed
* resolution: => worksforme
Comment:
I cannot reproduce this issue, generated `settings.py` contains
`DEFAULT_AUTO_FIELD`:
{{{
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
}}}
it's also defined in `polls/apps.py`:
{{{
class PollsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'polls'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32741#comment:2>
Comment (by Katie McLaughlin):
Ah, I see what I did wrong. I had a global Django installed so `django-
admin` was referencing the global 3.1.7 version instead of the 3.2.2 local
version. Fixing that generated the right template project for me, showing
the setting you see.
Sorry for the noise!
--
Ticket URL: <https://code.djangoproject.com/ticket/32741#comment:3>