📜  未定义主键类型时使用的自动创建的主键,默认为 'django.db.models.AutoField'. - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:39.781000             🧑  作者: Mango

代码示例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 add id in your models

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