Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#32741 closed Cleanup/optimization (worksforme)

Tutorial Part 2 throws models.W042 warnings when making migrations

Reported by: Katie McLaughlin Owned by: nobody
Component: Documentation Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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:

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

Change History (3)

comment:1 by Katie McLaughlin, 3 years ago

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.

comment:2 by Mariusz Felisiak, 3 years ago

Resolution: worksforme
Status: newclosed

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'

comment:3 by Katie McLaughlin, 3 years ago

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!

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