[Fixed]-How to Serialize BigIntegerField, TextField in serializer Django


This is because the django rest framework’s Serializer doesn’t have a TextField. Where your model has a TextField you need to use a CharField in the serializer.

CharField A text representation. Optionally validates the text to be
shorter than max_length and longer than min_length.

Corresponds to django.db.models.fields.CharField or

The documentation isn’t as clear about BigIntegerFields from models, but this line for the source code shows that IntegerField is again what you have to use in the serializer.



For text field you can follow the following convention

your_variable_name = serializers.CharField(style={'base_template': 'textarea.html'})

Suggested in rest framework documentation.


Replace TextField with CharField. Both have basically the same functionality, but serializers understand only the later.

Leave a comment