title: NOT NULL constraint failed: snippets_choice.post_id
body: <p>am trying to use the POST method here but it is throwing me an error. </p>
  
  <p>this is Models.py:</p>
  
  <pre><code>from django.db import models
  
  class Post(models.Model):
      post_text=models.CharField(max_length=200)
  
      def __str__(self):
          return self.post_text
  
  class Choice(models.Model):
      post=models.ForeignKey(Post, on_delete=models.CASCADE)
      choice_text=models.CharField(max_length=200)
      likes=models.IntegerField(default=0)
  
      def __str__(self):
          return self.choice_text
  </code></pre>
  
  <p>this is serializes.py:</p>
  
  <pre><code>from rest_framework import serializers
  from snippets.models import Post, Choice
  
  class PostSerializer(serializers.HyperlinkedModelSerializer):
      class Meta:
          model=Post
          fields=['id','post_text']
  
  class ChoiceSerializer(serializers.HyperlinkedModelSerializer):
      class Meta:
          model=Choice
          fields=['id','choice_text','likes']
  </code></pre>
  
  <p>this is views.py:</p>
  
  <pre><code>
  from django.shortcuts import render
  from rest_framework import generics
  from rest_framework.reverse import reverse
  from .models import Choice, Post
  from django.http import Http404
  from rest_framework.views import APIView
  from rest_framework.response import Response
  from rest_framework import status
  from snippets.serializers import ChoiceSerializer, PostSerializer
  
  class PostList(generics.ListCreateAPIView):
      queryset=Post.objects.all()
      serializer_class=PostSerializer
      name='post-list'
  
  class PostDetail(generics.RetrieveUpdateDestroyAPIView):
      queryset=Post.objects.all()
      serializer_class=PostSerializer
      name='post-detail'
  
  class ChoiceList(generics.ListCreateAPIView):
      queryset=Choice.objects.all()
      serializer_class=ChoiceSerializer
      name='choice-list'
  
  class ChoiceDetail(generics.RetrieveUpdateDestroyAPIView):
      queryset=Choice.objects.all()
      serializer_class=ChoiceSerializer
      name='choice-detail'
  
  class ApiRoot(generics.GenericAPIView):
      name='api-root'
  
      def get(self, request, *args, **kwargs):
          return Response({
          'posts': reverse(PostList.name, request=request),
          'choices': reverse(ChoiceList.name, request=request),
          }) 
  </code></pre>
  
  <p>urls.py:</p>
  
  <pre><code>urlpatterns=[
      path('post-list/', views.PostList.as_view(), name='post-list'),
      path('post-list/&lt;int:pk&gt;/', views.PostDetail.as_view()),
      path('choice-list/', views.ChoiceList.as_view(), name='choice-list'),
      path('choice-list/&lt;int:pk&gt;/', views.ChoiceDetail.as_view()),
      path('',views.ApiRoot.as_view(),name=views.ApiRoot.name),
  ]
  </code></pre>
  
  <p>when I try to post:</p>
  
  <pre><code>{ 
      "id":3
      "choice_text": "random text",
      "likes": 0
  }
  </code></pre>
  
  <p>I got this error:</p>
  
  <pre><code>IntegrityError at /choice-list/
  NOT NULL constraint failed: snippets_choice.post_id
  </code></pre>
  
  <p>if am providing the id, why it is throwing an error?</p>
  
  <p>even in Postman, it's asking me to put 'choice_text', even when am providing the choice_text.</p>