[Django]-Django.core.exceptions.FieldError: Unknown field(s) (body ) specified for Comment

28👍

You need to remove a white space at the end of 'body ' field, where you should have 'body' like below:

class CommentForm(forms.ModelForm):
    class Meta:
        model = Comment
        fields = ('name', 'email', 'body')

7👍

The same error also occurs if a model field with editable=False is included in a form’s fields. Removing the editable attribute on the model field fixes the error.

3👍

I wasted a lot of time because I accidentally put a comma after the field definition in Model

👤IML

2👍

if you don’t have any white space, then make "editable=TRUE" in models.py file.
for example:

class profile(models.Model):
    username=models.CharField(max_length=200, blank=True, null=True, editable=True)
    location=models.CharField(max_length=200, blank=True, null=True, editable=True)
    name=models.CharField(max_length=200, blank=True, null=True, editable=True)

and then re-lunch your development server.

1👍

remove the space in ‘body ‘
it will look like this

class CommentForm(forms.ModelForm):
    class Meta:
        model = Comment
        fields = ('name', 'email', 'body') 

1👍

I just had a variant of this problem where the spelling of the field name in the form was the same as in the model. And still I got the error.

I had declared the model field like this:

  body = BooleanField(name="The comment's body text")

The mistake was to say name where I wanted to say verbose_name.

As a result, there was indeed no field called body in the model, just like the error message claimed, rather the field was now called something much longer.

Leave a comment