Opened 5 years ago

Closed 4 months ago

Last modified 4 months ago

#18485 closed Cleanup/optimization (fixed)

Document behavior of PostgreSQL/Oracle when manually setting autoincrementing fields

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

Description

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 https://docs.djangoproject.com/en/dev/ref/databases/ page include a warning about this difference, and a reference to the 'sqlsequencereset' command.

Change History (5)

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 :)

comment:2 Changed 5 months ago by Tim Graham

As noted in ticket:28272#comment:3, Oracle identity columns (which will be created as of Django 2.0; 924a89e135fe54bc7622aa6f03405211e75c06e9) aren't affected.

comment:3 Changed 4 months ago by François Freitag

Has patch: set
Owner: changed from nobody to François Freitag
Status: newassigned
Version: 1.4master

comment:4 Changed 4 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 4f1eb64a:

Fixed #18485 -- Doc'd behavior of PostgreSQL when manually setting AutoField.

comment:5 Changed 4 months ago by Tim Graham <timograham@…>

In 712ce47:

[1.11.x] Fixed #18485 -- Doc'd behavior of PostgreSQL when manually setting AutoField.

Backport of 4f1eb64ad0bcebfae4075486855eb6b63355cc5a from master

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