#17415: Creating an object with an explicit primary key value causes the next
creation to fail under PostgreSQL
-------------------------------------+-------------------------------------
     Reporter:  niko@…               |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  SVN
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:  site admin create    |      Needs documentation:  0
  db orm                             |  Patch needs improvement:  0
    Has patch:  0                    |                    UI/UX:  0
  Needs tests:  0                    |
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by russellm):

 I just saw this ticket go past as part of the 1.4 rundown, and it occurred
 to me that the fix is obvious, and has precedence in Django's source tree.
 Once you've manually created *any* object with a primary key, you need to
 invoke the SQL generated by the sqlsequencereset management command. This
 finds the largest PK value, and sets the sequence to select the next
 available PK value. This is an issue on Postgres and Oracle, because they
 both use sequences for autogenerated PKs; MySQL and SQLite both use
 "largest PK + 1" internal mechanisms, IIRC.

 We already do this as part of fixture loading. Loading a fixture involves
 manually specifying a whole lot of primary key values; one of the last
 things the loaddata command does before committing is to reset the
 sequences. This ensures that the next object with an autogenerated PK
 value will have a valid PK value.

 From my reading, this bug would have existed for as long as the sites
 framework has existed; although it would have been masked on any site that
 loaded fixtures (since loading a single fixture would have reset the
 sequence as a side effect).

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17415#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to