[Django]-"Not a valid string." โ€“ error when trying save dict to TextField in Django Rest Framework

6๐Ÿ‘

โœ…

Try this in your serializer:

class ApiLogSerializer(serializers.ModelSerializer):
    incoming_data = serializers.JSONField() # change is here

    class Meta:
        model = ApiLog
        fields = ('incoming_data',)

This will convert your JSON dict to string and store in DB as Text.

Refer to the official DRF documentation for more details

๐Ÿ‘คJPG

0๐Ÿ‘

try with quotes?:

data = {..., 
        'incoming_data':'{"key1":"value1","key2":"value2"}'
       }
๐Ÿ‘คoj43085

Leave a comment