[Fixed]-Django DRF serializer on PrimaryKeyRelatedField

1👍

✅

The issue is there:

class ConversationSerializer(serializers.ModelSerializer):

    msg_conv = MessagesSerializer()

By doing this, you are saying that Conversation has a FK to Message. Therefore DRF tries to do the mapping and fails because it’s the oposit.

You just need to add the many=True argument to let DRF knows this is a reversed FK.

Leave a comment