missing required Charfield in django is saved as empty string and do not raise an error
<p>If I try to save incomplete model instance in Django 1.10, I would expect Django to raise an error. It does not seem to be the case.</p>

<p>models.py:</p>

<pre><code>from django.db import models

class Essai(models.Model):
    ch1 = models.CharField(max_length=100, blank=False)
    ch2 = models.CharField(max_length=100, blank=False)
</code></pre>

<p>So I have two fields not allowed to be empty (default behavior, <code>NOT NULL</code> restriction is applied by Django at MySQL table creation). I expect Django to rase an error if one of the fields is not set before storing.</p>

<p>However, when I create an incomplete instance, the data is stored just fine:</p>

<pre><code>&gt;&gt;&gt; from test.models import Essai
&gt;&gt;&gt; bouh = Essai()
&gt;&gt;&gt; bouh.ch1 = "some content for ch1"
&gt;&gt;&gt; bouh.save()
&gt;&gt;&gt; bouh.id
9
&gt;&gt;&gt; bouh.ch1
'some content for ch1'
&gt;&gt;&gt; bouh.ch2
''
&gt;&gt;&gt; 
</code></pre>

<p>I would have expected Django to raise an error. If I force <code>ch2</code> to <code>None</code>, however, it raises an error:</p>

<pre><code>&gt;&gt;&gt; bouh = Essai()
&gt;&gt;&gt; bouh.ch1 = "some content for ch1"
&gt;&gt;&gt; bouh.ch2 = None
&gt;&gt;&gt; bouh.save()
Traceback (most recent call last):
  (...)
    return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: NOT NULL constraint failed: test_essai.ch2
&gt;&gt;&gt; bouh.id
&gt;&gt;&gt; bouh.ch1
'some content for ch1'
&gt;&gt;&gt; bouh.ch2
&gt;&gt;&gt;
</code></pre>

<p>Is this normal behavior? Did I miss something? Why is Django not raising an error as default behavior in this simple case?</p>

<p>Thanks for your lights!</p>

<p><code>EDIT</code></p>

<p>I got a few replies pointing out the fact that in SQL empty string <code>""</code> is not equivalent to NULL, as stated in <a href="http://stackoverflow.com/questions/17816229/django-model-blank-false-does-not-work">Django model blank=False does not work?</a>
However, if we look at ModelForm behavior, there seem to be a inconsistency in django doc.</p>

<p>see question
<a href="http://stackoverflow.com/questions/39739029/followup-missing-required-charfield-in-django-modelform-is-saved-as-empty-stri">Followup : missing required Charfield in django Modelform is saved as empty string and do not raise an error</a></p>

<blockquote>
  <p>Use this,</p>
</blockquote>

<pre><code>from django.db import models

class Essai(models.Model):
    ch1 = models.CharField(max_length=100)
    ch2 = models.CharField(max_length=100)
</code></pre>

python mysql django