5

I've a foreign key in my model and this field can be null.

status = models.ForeignKey(Status, on_delete=models.SET_NULL, null=True, blank=True, related_name="status")

When i send a request with this field as null i get validation error saying

[
    {
        "status": [
            "This field may not be null."
        ]
    }
]

Even though I have set null=True I'm not sure why it's throwing me that validation error? Can anyone please help me with this.

Update 1:

This is the below sample serializers I'm using

class SampleSerializer(serializers.ModelSerializer):
    id = serializers.IntegerField(read_only=False)
    status = serializers.CharField()

    class Meta:
        model = model_name
        list_serializer_class = SampleListSerializerClass
        fields = ("status", ...few other model fields)
Aashay Amballi
  • 1,321
  • 3
  • 17
  • 39

0 Answers0