[Django] #26238: confusing error message: django.core.exceptions.FieldError: Unknown field(s) specified when including a BinaryField in ModelForm.Meta.fields

1,003 views
Skip to first unread message

Django

unread,
Feb 18, 2016, 12:56:40 PM2/18/16
to django-...@googlegroups.com
#26238: confusing error message: django.core.exceptions.FieldError: Unknown
field(s) specified when including a BinaryField in ModelForm.Meta.fields
-------------------------------+--------------------
Reporter: groovecoder | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26238>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 18, 2016, 3:36:54 PM2/18/16
to django-...@googlegroups.com
#26238: confusing error message: django.core.exceptions.FieldError: Unknown
field(s) specified when including a BinaryField in ModelForm.Meta.fields
--------------------------------------+------------------------------------
Reporter: groovecoder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Forms | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by charettes):

* needs_better_patch: => 0
* component: Uncategorized => Forms
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

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 the `PushAppForm` form class.

The reason behind the `FieldError` on `PushAppForm` creation is the fact
`BinaryField` are not
[https://docs.djangoproject.com/en/1.9/ref/models/fields/#editable
editable] by default for obvious reasons and such fields are ignored by
[https://docs.djangoproject.com/en/1.9/topics/forms/modelforms/#selecting-
the-fields-to-use model forms].

I suggest we adjust the message of the `FieldError` raised when an
existing `editable=False` field is explicitly specified through
`Meta.fields` and amend the `BinaryField`'s limitations documentation to
also mention it can't be used in forms by default.

--
Ticket URL: <https://code.djangoproject.com/ticket/26238#comment:1>

Django

unread,
Feb 20, 2016, 8:55:34 AM2/20/16
to django-...@googlegroups.com
#26238: confusing error message: django.core.exceptions.FieldError: Unknown
field(s) specified when including a BinaryField in ModelForm.Meta.fields
--------------------------------------+------------------------------------
Reporter: groovecoder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Forms | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by claudep):

* has_patch: 0 => 1
* version: 1.9 => master


Comment:

[https://github.com/django/django/pull/6170 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26238#comment:2>

Django

unread,
Feb 21, 2016, 2:12:49 PM2/21/16
to django-...@googlegroups.com
#26238: confusing error message: django.core.exceptions.FieldError: Unknown
field(s) specified when including a BinaryField in ModelForm.Meta.fields
-------------------------------------+-------------------------------------
Reporter: groovecoder | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26238#comment:3>

Django

unread,
Feb 22, 2016, 3:54:08 AM2/22/16
to django-...@googlegroups.com
#26238: confusing error message: django.core.exceptions.FieldError: Unknown
field(s) specified when including a BinaryField in ModelForm.Meta.fields
-------------------------------------+-------------------------------------
Reporter: groovecoder | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Forms | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"d43156e1e984d7e0848b7d4db218877a29d617b4" d43156e1]:
{{{
#!CommitTicketReference repository=""
revision="d43156e1e984d7e0848b7d4db218877a29d617b4"
Fixed #26238 -- Raised explicit error for non-editable field in ModelForm

Thanks Luke Crouch for the report and Simon Charette for the review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26238#comment:4>

Reply all
Reply to author
Forward
0 new messages