Django: Use my own primary key, should I specify unique = True?

I am reading this page: http://www.djangoproject.com/documentation/models/custom_pk/ , and the example does not have a unique = True list. I am wondering if they have a good reason to leave this, or if there is any reason, I should include it. My guess is that specifying primary_key = True does this automatically, though. Any thoughts?

+4
source share
2 answers

http://docs.djangoproject.com/en/1.1/ref/models/fields/#primary-key

Your assumption is true, primary_key = True means unique = True.

+6
source

Josh Wright's answer is correct, but I also recommend reading the text on relational databases. By definition, the primary key must be unique, so it will be a mistake if Django allows the primary key to be unique. I highly recommend The Database Design for Mortals: A Relational Database Design Guide (2nd Edition) by Michael Hernandez. He is full of valuable practical advice.

+2
source

Source: https://habr.com/ru/post/1300307/


All Articles