Non-unique primary_key

A non-unique primary key allows the same value to be used for multiple records thus multiple results could be returned for Model.objects.get(pk=1).

A primary key is used to uniquely identify each record in the Model's database table.

primary_key=True denotes the field is the primary key for the model.

primary_key=True implies null=False and unique=True.

If our GitHub code review bot spots this issue in your pull request it gives this advice:

django-doctorbotsuggested changes just now
models.py
1
+
class BlogPost(models.Model):
2
+
    id = models.UUIDField(primary_key=True, unique=False)

A non-unique primary key allows the same value to be used for multiple records thus multiple results could be returned for Model.objects.get(pk=1).

Read more
Update models.py
We're your Django code review copilot. Get code improvements right in your pull request with our GitHub code review bot.

Configuring this check

Code Review Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code non-unique-primary in your pyproject.toml file.

Read more about configuring Code Review Doctor.