autofield in django

  1. Import the necessary module:
from django.db import models
  1. Define a model class with the AutoField:
class YourModel(models.Model):
    your_auto_field = models.AutoField(primary_key=True)
  1. Make migrations to apply changes to the database schema:
python manage.py makemigrations
  1. Apply migrations to update the database:
python manage.py migrate
  1. Use the model in your application:
instance = YourModel.objects.create()

In this example, replace "YourModel" with the name of your model, and "your_auto_field" with the desired name for the AutoField.