Opened 17 years ago

Closed 17 years ago

#6598 closed (wontfix)

Oracle backend: primary key sequences don't increment if you provide the primary key

Reported by: graham_king <graham@…> Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: oracle sequence
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The trigger that the Oracle backend creates on every table only increments the sequence if you don't provide an ID yourself. If you pickle some objects out of one django project / database and unpickle them into another, they already have IDs, so the sequence doesn't move on. Next time you try to add an object (say through the admin interface), the save will fail with a unique primary key violation.

The workaround is the call "SELECT "+ mysequence +".nextval FROM DUAL" every time you save your unpickled object.

Change History (2)

comment:1 by graham_king <graham@…>, 17 years ago

For the workaround, I meant you run that SQL once for each object you insert that has it's own primary key, thereby incrementing the sequence by one each time. Your objects must have sequential IDs, which is the most common case. Apologies if that was not clear.

comment:2 by Erin Kelly, 17 years ago

Resolution: wontfix
Status: newclosed

The solution to this is to use fixtures to load objects from an external source. The manage.py loaddata command will automatically reset the sequences to the max pk values after loading the fixture.

You can also reset the sequences manually using the SQL generated by manage.py sqlsequencereset.

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