I want to disable automatic id creation in Django Models. Is it possible to do so? How?
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With