title: IntegrityError:NOT NULL constraint failed: chatapp_chat.message
body: <p>I'm writing chat application in Django and after subbing my message I get error: </p>
  
  <pre><code>IntegrityError at /chatapp/post/ NOT NULL constraint failed: chatapp_chat.message
  </code></pre>
  
  <p>This is my models.py:</p>
  
  <pre><code>from django.db import models
  from django.contrib.auth.models import User
  
  class Chat(models.Model):
      created = models.DateTimeField(auto_now_add=True)
      user = models.ForeignKey(User, blank=True, null=True)
      message = models.CharField(max_length=200)
  
      def __unicode__(self):
          return self.message
  </code></pre>
  
  <p>This is my view.py</p>
  
  <pre><code>def home(request):
      c = Chat.objects.all()
      return render(request, "chatapp/home.html", {'home': 'active', 'chat': c})
  
  def post(request):
      if request.method == "POST":
  
          msg = request.POST.get('msgbox', None)
  
          c = Chat(user=request.user, message=msg)
          if msg != '':
              c.save()
          return JsonResponse({ 'msg': msg, 'user': c.user.username })
      else:
          return HttpResponse('Request must be POST.')
  
  def messages(request):
      c = Chat.objects.all()
      return render(request, 'chatapp/messages.html', {'chat': c})
  </code></pre>
  
  <p>And .html</p>
  
  <pre><code>&lt;body&gt;
  
          &lt;div class="panel-heading"&gt;Chat Box&lt;/div&gt;
          &lt;div id="msg-list-div" class="panel-body"&gt;
              &lt;ul id="msg-list" class="list-group"&gt;
                  {% for obj in chat %}
                      {% if obj.user == request.user %}
                          &lt;li class="text-right list-group-item"&gt;{{ obj.message }}&lt;/li&gt;
                      {% else %}
                          &lt;li class="text-left list-group-item"&gt;{{ obj.message }}&lt;/li&gt;
                      {% endif %}
                  {% empty %}
                      &lt;li class="text-right list-group-item"&gt;No messages yet!&lt;/li&gt;
                  {% endfor %}
                  &lt;script&gt;
                      var chatlist = document.getElementById('msg-list-div');
                      chatlist.scrollTop = chatlist.scrollHeight;
                  &lt;/script&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
  
  
      &lt;form id="chat-form" method="post" action="/chatapp/post/"&gt;
          {% csrf_token %}
          &lt;div id="chat-bottom" class="input-group"&gt;
              &lt;input type="text" id="chat-msg" name="chat-msg" class="form-control"/&gt;
              &lt;span class="input-group-btn"&gt;
                  &lt;input class="btn btn-default" id="send" type="submit" value="Send"/&gt;
              &lt;/span&gt;
  </code></pre>
  
  <p>I've searched through lot of answers but couldn't find the right solution for my problem.</p>