Opened 13 years ago
Closed 11 years ago
#17713 closed Cleanup/optimization (fixed)
allows_primary_key_0 is misnamed
Reported by: | Claude Paroz | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | anssi.kaariainen@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In django/db/backends/__init__.py
:
# Can an object have a primary key of 0? MySQL says No. allows_primary_key_0 = True
This is not totally right. MySQL refuses 0 only if the primary key is an autoincrement key. See also comments in #17653. At the very least, the comment should be updated. And ideally, allows_primary_key_0 should be renamed as (for example) allows_auto_pk_0.
Change History (6)
comment:1 by , 13 years ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 11 years ago
PR: https://github.com/django/django/pull/1984
Later, in a separate ticket I will create a unit test for exercising the MySQL capability of using non-autoincrement primary key with value 0.
comment:3 by , 11 years ago
Has patch: | set |
---|
I guess the only concern here is whether or not setting this attribute on your own database backend is considered private API subject to change?
comment:4 by , 11 years ago
This is the separate ticket for adding unit test exercising the capability of having zero non-autoincrement primary key, #21517.
comment:5 by , 11 years ago
@timo: or we can add another attribute (allows_auto_pk_0) and keep this one (allows_primary_key_0).
comment:6 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This is a really minor issue, but also an easy one to fix.
If somebody with older MySQL versions could test this it would be valuable information. I have tested this on 5.1 where id INTEGER PRIMARY KEY accepts zero as a value. Based on that marking as accepted.
I think changing the name is the correct thing to do.