If you do not add a primarykey explicitly django will create a field `id` for you by default. Normally this is an autoincrement integer. see https://docs.djangoproject.com/en/2.1/topics/db/models/#automatic-primary-key-fields
You may name your primary key field to whatever you want. `pk` is an alias that will always be the field you defined as your primary key field. Normally you will be fine with the autocreated primary key fields in which case `id` and `pk` will have the same effect, but when you choose to give your field a different name `id` and `pk` will differ. In your code you should prefer `pk` over `id` for the above reasons On Fri, 2 Nov 2018 at 11:37, amit pant <[email protected]> wrote: > I want to know, what is main difference between pk and id on django. > Would appreciate if any one could help me. > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/d8f5be26-2319-4a81-82d0-97c5ddfcb048%40googlegroups.com > . > For more options, visit https://groups.google.com/d/optout. > -- Best Regards, Christian Ledermann Newark-on-Trent - UK Mobile : +44 7474997517 https://uk.linkedin.com/in/christianledermann https://github.com/cleder/ <*)))>{ If you save the living environment, the biodiversity that we have left, you will also automatically save the physical environment, too. But If you only save the physical environment, you will ultimately lose both. 1) Don’t drive species to extinction 2) Don’t destroy a habitat that species rely on. 3) Don’t change the climate in ways that will result in the above. }<(((*> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABCjzWr9K%2BRchN_4ik9mTY49crdGhpEq7A09ShojGbY3nMiM-Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

