[Django] #32741: Tutorial Part 2 throws models.W042 warnings when making migrations

17 views
Skip to first unread message

Django

unread,
May 11, 2021, 11:49:24 PM5/11/21
to django-...@googlegroups.com
#32741: Tutorial Part 2 throws models.W042 warnings when making migrations
------------------------------------------------+------------------------
Reporter: Katie McLaughlin | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------------+------------------------
Changes in Django 2.2 mean that the auto-created primary key changes
(https://docs.djangoproject.com/en/3.2/releases/3.2/#customizing-type-of-
auto-created-primary-keys) throw the associated warnings, as the Tutorial
Part 2 doesn't adjust for these.

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.

Django

unread,
May 11, 2021, 11:51:06 PM5/11/21
to django-...@googlegroups.com
#32741: Tutorial Part 2 throws models.W042 warnings when making migrations
-------------------------------------+-------------------------------------

Reporter: Katie McLaughlin | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
May 12, 2021, 1:54:35 AM5/12/21
to django-...@googlegroups.com
#32741: Tutorial Part 2 throws models.W042 warnings when making migrations
-------------------------------------+-------------------------------------

Reporter: Katie McLaughlin | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 3.2
Severity: Normal | Resolution:
| worksforme

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* 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>

Django

unread,
May 12, 2021, 2:03:57 AM5/12/21
to django-...@googlegroups.com
#32741: Tutorial Part 2 throws models.W042 warnings when making migrations
-------------------------------------+-------------------------------------

Reporter: Katie McLaughlin | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 3.2
Severity: Normal | Resolution:
| worksforme

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages