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 we spot this issue in your GitHub pull request we give this advice:

models.pymaintainabilityhigh
class BlogPost(models.Model):
    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
Protect your pull requests from over 40 types of common Django technical debts with our GitHub code review bot.

Configuring this check

Django 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 Django Doctor.