Auto-create primary key used when not defining a primary key type warning in Django
Solution 1:
Your models do not have primary keys. But they are being created automatically by django.
You need to choose 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 into settings.py
DEFAULT_AUTO_FIELD='django.db.models.AutoField'
or
class Topic(models.Model):
id = models.AutoField(primary_key=True)
...
Solution 2:
You have unintentionaly updated Django to 3.2 which warns you and as hint text suggest you have to set DEFAULT_AUTO_FIELD
as documented
This way you avoid unwanted migrations in future releases as
value of DEFAULT_AUTO_FIELD
will be changed to BigAutoField
You should set DEFAULT_AUTO_FIELD
explicitly to current DEFAULT_AUTO_FIELD
value
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
you could configure it even per app basis ( if you expect to build new apps with current style primary key)
from django.apps import AppConfig class MyAppConfig(AppConfig): default_auto_field = 'django.db.models.AutoField' name = 'my_app'
or even per-model ( discuraged )
from django.db import models class MyModel(models.Model): id = models.AutoField(primary_key=True)
You should also take care of version locking your requirements as you could introduce backward incompatible changes in production