Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Sequence in PostgreSQL is not updated when doing manual insert [RSS Feed]

#1 Nov. 23, 2005 18:25:35

Jacob K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Sequence in PostgreSQL is not updated when doing manual insert


On Nov 23, 2005, at 11:15 AM, pgross wrote:I've tracked down the problem, and it seems that when I do my manual
inserts, the sequence (cities_id_seq) that PostgreSQL uses for primary
keys isn't updated. Therefore, when I try to save my object with
django, the primary key collides with an already existing key.

I've implemented a simple fix by manually settings the sequence value
after I do my inserts, but I'm wondering why django/postgresql doesn't
do the right thing. Has anyone seen this before?Yeah, this is an annoying postgresql wart. We've run into it enoughthat we've rolled the fix into the django-admin utility. "django-admin sqlsequencereset <app>" will print out the statements to fixthe sequences.Programmatically, you can get at this SQL from thedjango.core.management.get_sql_sequence_reset() function.Jacob

Offline

#2 Nov. 24, 2005 10:47:45

p.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Sequence in PostgreSQL is not updated when doing manual insert


Thanks, I didn't notice that function before. Maybe the docs could
specify when and why you'd want to use it, such as my case above.

Paul

Offline

#3 Dec. 1, 2005 16:41:18

Joshua D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Sequence in PostgreSQL is not updated when doing manual insert


I've implemented a simple fix by manually settings the sequence value
after I do my inserts, but I'm wondering why django/postgresql doesn't
do the right thing. Has anyone seen this before?Yeah, this is an annoying postgresql wart. We've run into it enoughthat we've rolled the fix into the django-admin utility. "django-admin sqlsequencereset <DEFANGED_app>" will print out the statementsto fix the sequences.Well I wouldn't say this has anything to do with a postgresql wart asmuch as somebody not understanding how sequences work.A simple setval() would have solved the problem after load.

Joshua D. DrakeProgrammatically, you can get at this SQL from thedjango.core.management.get_sql_sequence_reset() function.Jacob--
The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: PLphp, PLperl -http://www.commandprompt.com/

Offline

  • Root
  • » Django
  • » Sequence in PostgreSQL is not updated when doing manual insert [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support