Discussion:
Fixtures auto-incrementing primary keys?
Nathaniel Whiteinge
2007-09-06 20:55:58 UTC
Permalink
Can fixtures have auto-incrementing primary keys or must you have
specific PKs in the the serialized json/xml/etc files? If not, is
there a reason for this?

I'm programmatically generating fixtures from Freebase.org queries for
a project. Although it's not a much extra work to add a pk counter, it
is the second time this has struck me as annoying. Would the devs be
open to a patch for this sort of thing?

Thanks,
- whiteinge


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
l***@gmail.com
2007-09-06 22:07:53 UTC
Permalink
Post by Nathaniel Whiteinge
Can fixtures have auto-incrementing primary keys or must you have
specific PKs in the the serialized json/xml/etc files? If not, is
there a reason for this?
I'm programmatically generating fixtures from Freebase.org queries for
a project. Although it's not a much extra work to add a pk counter, it
is the second time this has struck me as annoying. Would the devs be
open to a patch for this sort of thing?
Are you using PostgreSQL? If so you probably need to

select setval('sequence_name', x);

where x is the value of the last generated id

See pg's docs on this

http://www.postgresql.org/docs/8.2/interactive/functions-sequence.html

Lorenzo


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Russell Keith-Magee
2007-09-06 23:44:48 UTC
Permalink
Post by Nathaniel Whiteinge
Can fixtures have auto-incrementing primary keys or must you have
specific PKs in the the serialized json/xml/etc files? If not, is
there a reason for this?
This idea has occurred to me before, and I can see how it could be
useful, but I got caught up on one significant detail: how do you
handle references? When you specify the PK, you provide an identifier
to use as a cross reference. If this identifier no longer exists, what
do you use as a reference in its place?
Post by Nathaniel Whiteinge
I'm programmatically generating fixtures from Freebase.org queries for
a project. Although it's not a much extra work to add a pk counter, it
is the second time this has struck me as annoying. Would the devs be
open to a patch for this sort of thing?
You shouldn't even need to write a PK counter - just save the objects
without a primary key, and the database will allocate the next
available key. The issue is how to cross reference.

However, I am very much open to the general idea, as long as you can
provide a solution to the problem - and a patch would be even more
welcome.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Nathaniel Whiteinge
2007-09-08 07:04:12 UTC
Permalink
Thanks for the replies, both.
Post by Russell Keith-Magee
This idea has occurred to me before, and I can see how it could be
useful, but I got caught up on one significant detail: how do you
handle references? When you specify the PK, you provide an identifier
to use as a cross reference. If this identifier no longer exists, what
do you use as a reference in its place?
I hadn't thought that far ahead. You're right. I'll give it some
thought.
Post by Russell Keith-Magee
You shouldn't even need to write a PK counter - just save the objects
without a primary key, and the database will allocate the next
available key. The issue is how to cross reference.
Heh, whoops! It didn't occur to me to set the pk to None, I was just
omitting 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
-~----------~----~----~----~------~----~------~--~---

Loading...