[Fixed]-This field is required error in django

14👍

Use

Finished = models.IntegerField('Finished percentage', blank=True, null=True)

Read https://docs.djangoproject.com/en/1.4/ref/models/fields/#blank:

null is purely database-related, whereas blank is validation-related.

You might have defined the field without null=True first. Changing that in the code now won’t change the initial layout of the database. Use South for database migrations or change the database manually.

6👍

On a form you could set required=False on the field:

Finished = forms.IntegerField(required=False)

Or to avoid redefining the field on a ModelForm,

def __init__(self, *args, **kwargs):
    super(MyForm, self).__init__(*args, **kwargs)
    self.fields['Finished'].required = False
    #self.fields['Finished'].empty_label = 'Nothing' #optionally change the name
👤CJ4

2👍

Maybe a default value is needed

finished = models.IntegerField(default=None,blank=True, null=True)

Leave a comment