5π
β
To add an auto-increment field in django, you are supposed to use AutoField
You should define your id
field like this:
id = models.AutoField(primary_key=True)
If you want to name it as id
, you are not required to define the field, django does that for you.
A model without explicit id
field will still have a AutoField id
as a primary key.
π€v1k45
Source:stackexchange.com