primary key auto increment python django
Create a new model in your Django app's models.py file:
from django.db import models
class YourModelName(models.Model):
your_field = models.CharField(max_length=100)
Add 'id' as the primary key within the model:
class YourModelName(models.Model):
id = models.AutoField(primary_key=True)
your_field = models.CharField(max_length=100)
Run the migration to apply the changes to the database:
python manage.py makemigrations
python manage.py migrate