#25480 closed Uncategorized (invalid)
CharField + choices + default = fields.E008
Reported by: | Christopher Schäpers | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.9a1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Have this as your models.py:
from django.db import models from django.utils.translation import ugettext_lazy breakage_status = ( (ugettext_lazy("In queue"), 'queue'), (ugettext_lazy("Processing"), 'proces'), (ugettext_lazy("Done"), 'done'), ) class Breakage(models.Model): status = models.CharField(max_length=6, default="queue", choices=breakage_status)
Results in:
(project)kondou:project/ (master✗) $ ./manage.py check SystemCheckError: System check identified some issues: ERRORS: project.Breakage.status: (fields.E008) Invalid 'default' value: Value 'queue' is not a valid choice. System check identified 1 issue (0 silenced).
with default="queue"
(project)kondou:project/ (master✗) $ ./manage.py check SystemCheckError: System check identified some issues: ERRORS: project.Breakage.status: (fields.E008) Invalid 'default' value: Value "(<django.utils.functional.lazy.<locals>.__proxy__ object at 0x7ff17180d358>, 'queue')" is not a valid choice. System check identified 1 issue (0 silenced).
with default=breakage_status[0]
(project)kondou:project/ (master✗) $ ./manage.py check SystemCheckError: System check identified some issues: ERRORS: project.Breakage.status: (fields.E008) Invalid 'default' value: Value 'queue' is not a valid choice. System check identified 1 issue (0 silenced).
with default=breakage_status[0][1]
(project)kondou:project/ (master✗) $ ./manage.py check SystemCheckError: System check identified some issues: ERRORS: project.Breakage.status: (fields.E008) Invalid 'default' value: Ensure this value has at most 6 characters (it has 8). System check identified 1 issue (0 silenced).
with default=breakage_status[0][0]
.
Change History (3)
follow-up: 2 comment:1 by , 9 years ago
comment:2 by , 9 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Replying to collinanderson:
Hi,
Did you mean to do this?
breakage_status = ( ('queue', ugettext_lazy("In queue")), ('process', ugettext_lazy("Processing")), ('done', ugettext_lazy("Done")), )
No I meant it in reverse … It's wrong I just realized. Wondering how this worked out for me in 1.8 … Closing …
comment:3 by , 9 years ago
I'm afraid it wasn't working correctly in 1.8 and the newly added 'fields.E008'
check spotted it.
You might want to investigate if your database doesn't contain 'Done'
entry for this field or 'In que'
and 'Process'
if you're using MySQL which does silent truncation of value when it cannot fit a VARCHAR
instead of raising an integrity error.
Hi,
Did you mean to do this?