#2855 closed defect (wontfix)
[patch] BooleanField should use False as default (unless provided)
Reported by: | Chris Beaven | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | normal | Keywords: | BooleanField NullBooleanField |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When creating models, BooleanField
s which haven't explicitly been given a default
have to be specifically set or a SQL error will occur (because the default value will be ). Simple solution is to force the default to False
if no default is given.
# The model class TestModel(models.Model): check = models.BooleanField() # then in code.. t = TestModel() t.save() # will error, because the boolean field will return the default of '' instead of False
Attachments (1)
Change History (9)
by , 18 years ago
Attachment: | boolean_default.patch added |
---|
comment:1 by , 18 years ago
I'm not sure I understand the bug here; any type of field should throw an error if it doesn't have null=True
and you don't supply a value.
comment:2 by , 18 years ago
null=True
doesn't make sense to me for BooleanField
s because this are only two states it can be in - I'm not wanting a NullBooleanField
. What does make sense is that if the default hasn't been specified as True
for a boolean, you assume False
.
Here are the local vars for the SQL error raised:
params = ('',) sql 'INSERT INTO "project.test_model" ("check") VALUES (%s)'
comment:4 by , 18 years ago
You need the null=True to check if the value has been set or not. So BooleanField is actually a triple-state variable: True, False and unset.
If null=True should be the default case is of course highly application dependant. In my applications so far I always used null=True, but your mileage my vary.
comment:5 by , 18 years ago
Bastian, in Django there are two similar fields: BooleanField and NullBooleanField.
BooleanField can only have one of two states: True
or False
.
comment:6 by , 18 years ago
Keywords: | BooleanField NullBooleanField added |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:7 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Closing this as wontfix for the reasons pointed out in the above comments.
simple fix