#28272: PostgreSQL: AutoField sequences don't increment when inserting objects
with
an explicitely specified PK
-------------------------------------+-------------------------------------
Reporter: François Freitag | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: postgresql sequence | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tim Graham):
I'm doubtful that trying to make Django automatically set the sequence is
a good idea. In particular, I'm thinking about thread safety of such a
solution. Quoting James Bennett from comments 1 & 3 of #11423,
When you do [manually specify a primary key] on Postgres, you need to
reset the sequence from which automatic values are generated (since that
sequence doesn't know that you manually inserted some values, and so those
values are no longer available for use); this is a known feature of
Postgres, and Django provides a management command
([https://docs.djangoproject.com/en/dev/ref/django-admin/#sqlsequencereset
sqlsequencereset]) which will output the appropriate SQL for you to run to
reset the sequence. \\ \\
Friendly or not, this is the way Postgres, Oracle, DB2 and many other
databases work. MySQL and SQLite are really more the exceptions here,
since sequences are part of the SQL standard.
--
Ticket URL: <https://code.djangoproject.com/ticket/28272#comment:4>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/073.d71b97b487a8a224976885c5e71eaf7c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.