Discussion:
Auto increment in model primarykey
Vicky
2009-04-21 11:48:28 UTC
Permalink
I have a table with an 'id' field (Primary Key). When I insert the
data using admin interface it is asking me for the value of the
primary key field. But I want it to be filled automatically. Is there
a way to do it?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Anatoliy
2009-04-21 12:07:06 UTC
Permalink
Try to remove id field from model description. Django handles it
automatically.
Post by Vicky
I have a table with an 'id' field (Primary Key). When I insert the
data using admin interface it is asking me for the value of the
primary key field. But I want it to be filled automatically. Is there
a way to do it?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Mike Ramirez
2009-04-21 12:15:37 UTC
Permalink
Post by Anatoliy
Try to remove id field from model description. Django handles it
automatically.
Post by Vicky
I have a table with an 'id' field (Primary Key). When I insert the
data using admin interface it is asking me for the value of the
primary key field. But I want it to be filled automatically. Is there
a way to do it?
you can also have

id = AutoField(primary_key=True) or id = IntegerField(primary_key=True)

http://docs.djangoproject.com/en/dev/ref/models/instances/#auto-incrementing-primary-keys

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


Mike
--
This is the first age that's paid much attention to the future, which is a
little ironic since we may not have one.
-- Arthur Clarke
Vicky
2009-04-21 13:19:41 UTC
Permalink
Thanks a lot man. It worked. I just made it as AutoField :)
Post by Mike Ramirez
Post by Anatoliy
Try to remove id field from model description. Django handles it
automatically.
Post by Vicky
I have a table with an 'id' field (Primary Key). When I insert the
data using admin interface it is asking me for the value of the
primary key field. But I want it to be filled automatically. Is there
a way to do it?
you can also have
id = AutoField(primary_key=True) or id = IntegerField(primary_key=True)
http://docs.djangoproject.com/en/dev/ref/models/instances/#auto-incre...
http://docs.djangoproject.com/en/dev/ref/models/fields/#primary-key
Mike
--
This is the first age that's paid much attention to the future, which is a
little ironic since we may not have one.
                -- Arthur Clarke
 signature.asc
< 1KViewDownload
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Loading...