title: Django REST Framework: Integrity error on not null column when posting data
body: <p>I have these two related models:</p>
  <pre><code>class EndPoint(TimeStampedModel):
      name = models.CharField(max_length=100)
      url = models.CharField(max_length=100)
      description = models.CharField(max_length=100)   
  
  class Parameter(TimeStampedModel):
      name = models.CharField(max_length=100)
      label = models.CharField(max_length=100)
      required = models.BooleanField()
      type = models.CharField(max_length=100)
      format = models.CharField(max_length=100, null = True)
      endpoint = models.ForeignKey(EndPoint, related_name=&quot;parameters&quot;,null = True, on_delete=models.CASCADE) 
  </code></pre>
  <p>Which map to these seralizers:</p>
  <pre><code>class ParameterRelationSerializer(serializers.ModelSerializer):
      class Meta:
          model = Parameter
          fields = ('id', 'name', 'label', 'required','type','format')
      
  class EndPointSerializer(serializers.ModelSerializer):
      parameters = ParameterRelationSerializer(many = True, read_only=False)
  
      class Meta:
          model = EndPoint
          fields = ('id', 'name', 'url', 'description', 'parameters')
  
      def create(self, validated_data):
          parameters = validated_data.pop('parameters')
          endPoint = EndPoint.objects.create(**validated_data)
          for parameter_relation in parameters:
              Parameter.objects.create(endpoint=endPoint, **parameter_relation)
          return endPoint
  </code></pre>
  <p>Now, when I try to POST a new endpoint with this data:</p>
  <pre><code>{
     &quot;url&quot;:&quot;http://the.url.com&quot;,
     &quot;name&quot;:&quot;Dummy url&quot;,
     &quot;description&quot;:&quot;This is a dummy url&quot;,
     &quot;parameters&quot;:[
        {
           &quot;name&quot;:&quot;dummyparam&quot;,
           &quot;type&quot;:&quot;dummy&quot;,
           &quot;label&quot;:&quot;dummy_parameter&quot;
        }
     ]
  }
  </code></pre>
  <p>I get a 500 error saying this:</p>
  <blockquote>
  <p>IntegrityError at /catalogs/endpoints/</p>
  <p>null value in column &quot;required&quot; violates not-null constraint</p>
  <p>DETAIL:  Failing row contains (6, 2017-08-14 12:01:52.857902+00, 2017-08-14 12:01:52.857984+00, dummyparam, dummy_parameter, null, dummy, null, 6).</p>
  </blockquote>
  <p>Basically, it is complaining about the not-null 'required' attribute (in the Parameter model) being missing thus causing a DB error.</p>
  <p>My question is, shouldn't this be handled by the serializer validator instead of throwing a DB exception? In fact, I have another bunch of not-null attributes that trigger a validation error when missing in the json data.</p>