I had a custom primary key that need to be set up on a particular data in a model.
This was not enough, as an attempt to insert a duplicate number succeeded. So now when i replace primary_key=True
to unique=True
it works properly and rejects duplicate numbers!!. But according this document (which uses fields).
primary_key=True
implies null=False
and unique=True.
Which makes me confused as in why does
it accept the value in the first place
with having an inbuilt unique=True
?
Thank you.
Updated statement:
personName = models.CharField(primary_key=True,max_length=20)
Copyright Notice:Content Author:「Nagaraj Tantri」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/6039443/primary-key-and-unique-key-in-django