autofield in django
- Import the necessary module:
from django.db import models
- Define a model class with the AutoField:
class YourModel(models.Model):
your_auto_field = models.AutoField(primary_key=True)
- Make migrations to apply changes to the database schema:
python manage.py makemigrations
- Apply migrations to update the database:
python manage.py migrate
- 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.