Avoid primary key in Django models.py

386 views
Skip to first unread message

jagadishreddy bommareddy

unread,
Aug 4, 2017, 8:07:19 AM8/4/17
to Django users
I am using Django frame work in that models.py in any field i don't want primarykey how can i avoid primary key

Matthew Pava

unread,
Aug 4, 2017, 10:33:06 AM8/4/17
to django...@googlegroups.com

You can’t.  You can change what field is the primary key, but you can’t remove the primary key.  Just specify primary_key=True on the field you would like to make your primary key.

From the docs:

Each model requires exactly one field to have primary_key=True (either explicitly declared or automatically added).

 

https://docs.djangoproject.com/en/1.11/topics/db/models/#automatic-primary-key-fields

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/c11a9e2d-b1e2-4e2f-9e6c-b6c74589efe0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Samuel Dorsaz

unread,
Aug 4, 2017, 12:41:56 PM8/4/17
to Django users
if you remove your primary key, you will not be able to identify your record in your database, could you please precise what do you want to achieve by doing this ?
Reply all
Reply to author
Forward
0 new messages