Opened 5 years ago

Last modified 5 years ago

#18485 new Cleanup/optimization

Document behavior of PostgreSQL/Oracle when manually setting autoincrementing fields

Reported by: greg.nicholas@… Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords: postgresql oracle autofield
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


As described in #11423, certain DB backends will not automatically set the sequence number for AutoField-based primary keys if the PKs are explicitly set.

As the ticket discussion states, this is a known feature of PostgreSQL and Oracle, and the 'sqlsequencereset' management command exists to get the sequence in sync. MySQL and SQLite handle the resetting automatically.

Although this difference is inherent at the database level, nothing in Django's database documentation makes this apparent. I would argue that typical Django users would be completely unaware of this issue (as was I, coming from a MySQL background). To me, it looked like a bug in the ORM or in psycopg2.

I suggest that the page include a warning about this difference, and a reference to the 'sqlsequencereset' command.

Change History (1)

comment:1 Changed 5 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

I think I'd rather put this in the documentation of AutoField. Well, the person who writes the patch get to choose :)

Note: See TracTickets for help on using tickets.
Back to Top