Discussion:
loaddata against postgresql doesn't update primary key's sequence 'last_value' ?
Jon Ballard
2007-04-04 02:28:48 UTC
Permalink
Hello everybody, I'm new. Django is the bomb.. my app is coming
together quickly.

Now to my issue..

I dumped my database to json and tried to ingest it back in. Seemed
to work fine at first -- everything was there -- but it turns out no
new records can be added because the sequence field 'last_value' for
all the auto primary keys was left at 1, despite many records being
added to the respective tables. Now I tend to think this might
actually be an issue with Psycopg, but why would it manifest itself
only when using loaddata?

My setup:
Django 0.96
Ubuntu 6.10 (Edgy)
PostgreSQL 8.1.8-0ubuntu6.10
Psycopg 1.1.21-7

This is the error when trying to add a new record:
IntegrityError at /admin/spots/spot/add/
ERROR: duplicate key violates unique constraint "spots_spot_pkey"
INSERT INTO "spots_spot"

Anyone have any ideas? Am I doing something wrong perhaps? Thanks
for any help.

I'll continue to research of course..

-Jon


--~--~---------~--~----~------------~-------~--~----~
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-04-04 02:37:45 UTC
Permalink
Post by Jon Ballard
Hello everybody, I'm new. Django is the bomb.. my app is coming
together quickly.
Glad you like it.
Post by Jon Ballard
Anyone have any ideas? Am I doing something wrong perhaps? Thanks
for any help.
I don't think you're doing anything wrong - I've had similar comments
made to me privately by some of my work colleagues. I haven't had a
chance to look into the issue yet.
Post by Jon Ballard
I'll continue to research of course..
If you find out anything, feel free to let me know. In the meantime,
I've opened ticket #3915 to track the problem.

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
-~----------~----~----~----~------~----~------~--~---
z***@gmail.com
2007-04-04 17:02:58 UTC
Permalink
Post by Jon Ballard
Hello everybody, I'm new. Django is the bomb.. my app is coming
together quickly.
Now to my issue..
I dumped my database to json and tried to ingest it back in. Seemed
to work fine at first -- everything was there -- but it turns out no
new records can be added because the sequence field 'last_value' for
all the auto primary keys was left at 1, despite many records being
added to the respective tables. Now I tend to think this might
actually be an issue with Psycopg, but why would it manifest itself
only when using loaddata?
Django 0.96
Ubuntu 6.10 (Edgy)
PostgreSQL 8.1.8-0ubuntu6.10
Psycopg 1.1.21-7
IntegrityError at /admin/spots/spot/add/
ERROR: duplicate key violates unique constraint "spots_spot_pkey"
INSERT INTO "spots_spot"
Anyone have any ideas? Am I doing something wrong perhaps? Thanks
for any help.
I'll continue to research of course..
-Jon
I think you can fix it by running something like:

$ python manage.py sqlsequencereset | psql mydbname

When you load data with the primary keys already set it doesn't update
the postgres sequence generator. There's a ticket about how this
affects fixture loading:

http://code.djangoproject.com/ticket/3790

Zach


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Jon Ballard
2007-04-04 19:32:24 UTC
Permalink
Post by z***@gmail.com
$ python manage.py sqlsequencereset | psql mydbname
When you load data with the primary keys already set it doesn't update
the postgres sequence generator. There's a ticket about how this
http://code.djangoproject.com/ticket/3790
Zach
Ah, thanks. That's certainly an easy enough workaround (perhaps you
could even call it the solution). I did a manual fix for each
sequence using SETVAL but this would be much simpler, and automatic.

Anyway, I added a "see also #3790" comment to the new ticket Russ
created yesterday (#3915).

-Jon


--~--~---------~--~----~------------~-------~--~----~
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-04-05 00:33:44 UTC
Permalink
Post by z***@gmail.com
$ python manage.py sqlsequencereset | psql mydbname
Correct. I'll be merge something similar to that into the loaddata code.
Post by z***@gmail.com
When you load data with the primary keys already set it doesn't update
the postgres sequence generator. There's a ticket about how this
http://code.djangoproject.com/ticket/3790
Thanks for that Zach - I didn't notice this one go past. I've closed
off #3915 as a duplicate.

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
-~----------~----~----~----~------~----~------~--~---
Russell Keith-Magee
2007-04-06 02:30:11 UTC
Permalink
Post by Russell Keith-Magee
Post by z***@gmail.com
http://code.djangoproject.com/ticket/3790
Thanks for that Zach - I didn't notice this one go past. I've closed
off #3915 as a duplicate.
FYI - I've just committed [4937], which has a patch (and a regression
test) for this problem. Thanks for the suggestion on a fix, Zach.

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
-~----------~----~----~----~------~----~------~--~---

Loading...