title: Django REST Framework NOT NULL constraint failed
body: <p>when I try to create a new Post by posting the following JSON:</p>
  
  <pre><code>{
      "text": "test",
       "location": 1
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>NOT NULL constraint failed: grapevineapp_post.location_id
  </code></pre>
  
  <p>models.py:</p>
  
  <pre><code>class Location(models.Model):
      name = models.CharField(max_length=80)
      created = models.DateTimeField(auto_now_add=True)
      def __str__(self):
          return self.name
  
  class Post(models.Model):
      text = models.CharField(max_length=512)
      owner = models.ForeignKey('auth.User', related_name='posts', on_delete=models.CASCADE)
      location = models.ForeignKey(Location, related_name='posts', on_delete=models.CASCADE)
      created = models.DateTimeField(auto_now_add=True)
      def __str__(self):
          return self.text
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>class PostList(generics.ListCreateAPIView):
      permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
      queryset = Post.objects.all()
      serializer_class = PostSerializer
      def perform_create(self, serializer):
          serializer.save(owner=self.request.user)
  
  class PostDetail(generics.RetrieveUpdateDestroyAPIView):
      permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
      queryset = Post.objects.all()
      serializer_class = PostSerializer
  </code></pre>
  
  <p>Serializers.py</p>
  
  <pre><code>class PostSerializer(serializers.Serializer):
      id = serializers.IntegerField(read_only=True)
      text = serializers.CharField(required=False, allow_blank=True, max_length=512)
      owner = serializers.ReadOnlyField(source='owner.username')
      location = serializers.PrimaryKeyRelatedField(many=False, read_only=True)
  
      def create(self, validated_data):
          return Post.objects.create(**validated_data)
  
      def update(self, instance, validated_data):
          instance.text = validated_data.get('text', instance.text)
          instance.location = validated_data.get('location', instance.location)
          instance.save()
          return instance
  class UserSerializer(serializers.ModelSerializer):
      posts = serializers.PrimaryKeyRelatedField(many=True, queryset=Post.objects.all())
  
      class Meta:
          model = User
          fields = ('id', 'username', 'posts')
  </code></pre>
  
  <p>DB has already been cleared. Locations have been created by using the admin interface. I know that the issue is something trivial, but I just can't get it to work. </p>