Opened 18 years ago
Last modified 16 years ago
#2160 closed defect
Can't use value of 0 for primary key — at Version 3
Reported by: | fgutierrez AT aureal.com.pe | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The DB API uses a 'bool(pk_val) == false' check to determine if a model instance is a new item needs to be INSERTed, or an existing entry that needs to be UPDATEd.
Most databases use PK's starting at 1, but if you try to manually use a pk value of 0, the object cannot be saved - it can only be recreated.
Change History (3)
comment:1 by , 18 years ago
Component: | Documentation → Database wrapper |
---|---|
Owner: | changed from | to
Severity: | major → critical |
comment:2 by , 18 years ago
Summary: | Documentation How Django knows to Update vs Insert not correct → How Django knows to Update vs Insert not correct for PK values that evaluates to False |
---|
comment:3 by , 18 years ago
Description: | modified (diff) |
---|---|
priority: | high → normal |
Severity: | critical → normal |
Summary: | How Django knows to Update vs Insert not correct for PK values that evaluates to False → Can't use value of 0 for primary key |
Version: | → SVN |
Original ticket description covered two problems. First problem was resubmitted as #3118, and has since been resolved. Ticket description has been revised to reflect the remaining problem.
I have realized also that if i have that kind of PK values i could never update the object, i can get the object, change its values but once I use save then the exact same problem raises and Django tries to do an Insert, so raising a Duplicate Key exception.