3

I am using Django REST Framework and I have a MyNodel with a related MyOtherModel in a many-to-one relationship:

models.ForeignKey(MyModel, related_name="my_other_models", blank=True, null=True)

Although blank=True, null=True, when I try to post a MyModel JSON without a my_other_models field I get a "this field is required" error.

Ben RR
  • 913
  • 2
  • 10
  • 15
  • It would be much easier for us to help you if you provide the traceback and the view where you try to create MyNodel object – Adilet Maratov Oct 25 '16 at 10:58

1 Answers1

7

In your serializer, you need to add required=False.

field = MyModelSerializer(required=False)
1GDST
  • 821
  • 1
  • 8
  • 13