django auto increment field

  1. In your Django model, define an IntegerField with the primary_key and auto_now_add parameters to enable auto-increment and automatic assignment of current date and time when the object is first created.
  2. Set unique=True to ensure that each value in the field is unique.
  3. You can also add editable=False to make sure the field value is not editable once the object is created.
  4. After making these changes, run the Django migration command to apply the changes to your database schema.