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 Russell Keith-Magee)

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 fgutierrez, 18 years ago

Component: DocumentationDatabase wrapper
Owner: changed from Jacob to Adrian Holovaty
Severity: majorcritical

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.

comment:2 by anonymous, 18 years ago

Summary: Documentation How Django knows to Update vs Insert not correctHow Django knows to Update vs Insert not correct for PK values that evaluates to False

comment:3 by Russell Keith-Magee, 18 years ago

Description: modified (diff)
priority: highnormal
Severity: criticalnormal
Summary: How Django knows to Update vs Insert not correct for PK values that evaluates to FalseCan'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.

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