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: | 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:2 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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
.