1

I have a table in postgres with a column description that had the type varchar(2000), so in django:

description = serializers.CharField(......., max_length = 2000)

I want to change the description column in postgres to type text

Can I leave the description as a charfield? Or do I have to change it to a textfield? I still want to have max_length specified but change it to 5000, ie:

description = serializers.CharField(......., max_length = 5000)

I've tried to read the docs: https://www.django-rest-framework.org/api-guide/fields/#charfield, but I didn't see it being stated explicitly.

From what I've seen, it says:

CharField corresponds to django.db.models.fields.CharField or django.db.models.fields.TextField

I'm guessing that means it's ok?

I also looked around on stackoverflow: What's the difference between CharField and TextField in Django?, but I didn't see it being stated explicitly either.

Mark
  • 3,138
  • 5
  • 19
  • 36
  • 1
    The difference is that by default `CharField` will be presented as `Input` widget and `TextField` will be presented as `Textarea`. I use `CharField` as in most cases I want `Input` and in those case that I don't I can override the widget to be `TextArea`. In Postgres they are essentially the same thing especially as you can declare `varchar` with no length specification. See section *Tip* here [Character types](https://www.postgresql.org/docs/current/datatype-character.html). – Adrian Klaver Mar 28 '22 at 21:16

0 Answers0