[Django]-Django ORM cannot auto set primary key for model after loading data from legacy db

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

Leave a comment