I saw the django documents use both sometimes? Are they identical? What's the difference and where is the reference? I only see documentation of pk.
BTW, does django reference cover all the methods of its classes?
Django by default makes a primary key field on each model named " id ", with a type of AutoField .
By default, Django adds an id field to each model, which is used as the primary key for that model. You can create your own primary key field by adding the keyword arg primary_key=True to a field. If you add your own primary key field, the automatic one will not be added.
pk is short for primary key, which is a unique identifier for each record in a database. Every Django model has a field which serves as its primary key, and whatever other name it has, it can also be referred to as "pk".
It doesn't matter. pk is more independent from the actual primary key field i.e. you don't need to care whether the primary key field is called id or object_id or whatever. It also provides more consistency if you have models with different primary key fields.
pk
is the attribute that contains the value of the primary key for the model. id
is the name of the field created as a primary key by default if none is explicitly specified.
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