How to fix Django warning “(models.W042) Auto-created primary key used when not defining a primary key type”?

Your models do not have primary keys. But they are being created automatically by django.

You need to choose the type of auto-created primary keys:
https://docs.djangoproject.com/en/3.2/releases/3.2/#customizing-type-of-auto-created-primary-keys (new in Django 3.2)

Either add this to settings.py:
DEFAULT_AUTO_FIELD='django.db.models.AutoField'

or

class Topic(models.Model):
    id = models.AutoField(primary_key=True)
    ...

Leave a Comment

tech