Opened 9 years ago
Closed 9 years ago
#26238 closed Cleanup/optimization (fixed)
confusing error message: django.core.exceptions.FieldError: Unknown field(s) specified when including a BinaryField in ModelForm.Meta.fields
Reported by: | luke crouch | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I had a Model
with a CharField
:
class PushApplication(models.Model): jws_key = models.CharField(blank=True, max_length=255)
I changed it to a BinaryField
:
class PushApplication(models.Model): jws_key = models.BinaryField(blank=True)
When I tried to run makemigrations:
$ python manage.py makemigrations ... django.core.exceptions.FieldError: Unknown field(s) (jws_key) specified for PushApplication
The problem was that I had a ModelForm
with jws_key
in the fields:
class PushAppForm(ModelForm): class Meta: fields = ['name', 'jws_key']
I removed jws_key
from the ModelForm
and it works.
But the error message sent me on an hour long web search trying to find out why changing a CharField
to BinaryField
would break migrations.
Change History (4)
comment:1 by , 9 years ago
Component: | Uncategorized → Forms |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:3 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
Hi groovecoder,
In fact the exception you encountered has nothing to do with
makemigrations
; you should be able to also trigger it by simply importing the module defining thePushAppForm
form class.The reason behind the
FieldError
onPushAppForm
creation is the factBinaryField
are not editable by default for obvious reasons and such fields are ignored by model forms.I suggest we adjust the message of the
FieldError
raised when an existingeditable=False
field is explicitly specified throughMeta.fields
and amend theBinaryField
's limitations documentation to also mention it can't be used in forms by default.