ModelForm won't validate because missing value, but model field has null=True
<p>I have a problem where my <code>ModelForm</code> is trying to assign <code>''</code> to a field (it saves fine if I actually provide the primary key of the <code>Product</code>, but it's not a compulsory field, and won't save if the field is left blank). I take it that the ORM it's trying to set that field to <code>''</code>but:</p>

<ul>
<li>Shouldn't <code>''</code> be coerced to <code>None</code>, and; </li>
<li>Why isn't the model form trying to set that field to <code>None</code> in the first place instead of
<code>''</code>?</li>
</ul>

<p>models.py</p>

<pre><code>class Question(models.model):
    fk_product = models.ForeignKey(Product, on_delete=models.SET_NULL, null=True, related_name="product_question")
</code></pre>

<p>forms.py</p>

<pre><code>class QuestionForm(forms.ModelForm):
    fk_product=forms.ChoiceField(required=False)
    class Meta:
        model = Question
        fields = ['fk_product',]
</code></pre>

<p>The error:</p>

<blockquote>
  <p>Cannot assign "''": "Question.fk_product" must be a "Product"
  instance.</p>
</blockquote>

<p>The view code that produces the error:</p>

<pre><code>    QuestionModelFormset = modelformset_factory(Question,
                                form=QuestionForm,
                                extra=1)
    question_formset = QuestionModelFormset(
                            data=request.POST,
                            files=request.FILES,
                            queryset=Question.objects.all())
    if not question_formset.is_valid(): #error occurs on this line
</code></pre>

<p>Try adding <code>blank=True</code> too.</p>

<p><code>null=True</code> means that this field is allowed to be NULL in database.</p>

<p><code>blank=True</code> means it can be submitted without a value in forms. Otherwise it must have value.</p>

python django