using the Django REST Framework 2.0.
Here is my model class:
class Mission(models.Model):
assigned_to = models.ForeignKey('auth.User',
related_name='missions_assigned',
blank = True)
Here is my view class:
class MissionList(generics.ListCreateAPIView):
model = Mission
serialize_class = MissionSerializer
The multipart form is rendered in the browser with empty choice for assigned_to
field.
When posting raw JSON, I get the following error message:
Cannot assign None: "Mission.assigned_to" does not allow null values.
It is showing error because you need to add null=True in your field in order to send null value in the database.
The
blank
option is used in the form validation, and thenull
is used when writing to database.So you might add
null=True
to that field.