Reputation: 121
I want to disable automatic id creation in Django Models. Is it possible to do so? How?
Upvotes: 8
Views: 10493
Reputation: 14331
As mentioned in the reply, you need to declare a primary key on a non-AutoField. For example:
from django.db import models
class Person(models.Model):
username = CharField(primary_key=True, max_length=100)
first_name = CharField(null=True, blank=True, max_length=100)
Please note, setting a field to primary_key=True
automatically makes it unique and not null. Good luck!
Upvotes: 6