Skip to content Skip to sidebar Skip to footer

Violation Not-null Constraint. With A Foreighkey (not User) While Trying To Post In Django Restframework

This problem is commented in the whole Internet, but I don't know why, it's almost always with the user. In my case, the problem is not with the User. I have this model: class Do

Solution 1:

You don't have any details_sample field in your serializer so it is simply discarded from the data.

Solution 2:

I solved it writing this in the ViewSet

defperform_create(self, serializer):
    serializer.save(
        details_sample=DocumentDetailSample.objects.filter(Q(id=self.request.data['details_sample']))[0],
        user_id=self.request.user)

It's not beautiful, but it works. If someone knows a better way, please tell me.

Post a Comment for "Violation Not-null Constraint. With A Foreighkey (not User) While Trying To Post In Django Restframework"