# TextField or Charfield?

**URL:** <https://forum.djangoproject.com/t/textfield-or-charfield/11432>\
**Category:** Using Django\
**Created:** [January 7, 2022, 7:28am UTC](https://forum.djangoproject.com/t/textfield-or-charfield/11432 "2022-01-07T07:28:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sammeeey](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sammeeey/32/7340_2.png) [@Sammeeey](https://forum.djangoproject.com/u/Sammeeey)\
**Post date:** [January 7, 2022, 7:28am UTC](https://forum.djangoproject.com/t/textfield-or-charfield/11432/1 "2022-01-07T07:28:42Z")

</div>

In the Django [Docs for the TextField](https://docs.djangoproject.com/en/4.0/ref/models/fields/#textfield) they say:

> If you specify a `max_length` attribute, it will be reflected in the `Textarea` widget of the auto-generated form field. However it is not enforced at the model or database level. Use a [`CharField`](https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.CharField) for that.

Does this mean that I may define a max\_length, but if my area on the frontend is to small than the text might be cropped?  
Considering the Charfield which is described as…

> A string field, for small- to large-sized strings.

I am wondering "what is a large-sized string - 500, 1000, 10000 characters?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 7, 2022, 12:55pm UTC](https://forum.djangoproject.com/t/textfield-or-charfield/11432/2 "2022-01-07T12:55:47Z")

</div>

> [@Sammeeey](#):
>
> Does this mean that I may define a max\_length, but if my area on the frontend is to small than the text might be cropped?

They’re not talking about the physical size of the text area.

If you define `max_length`, _that_ is the number of characters that the _field in the browser_ will be initialized to accept. (Subject to being changed by JavaScript, malicious users, etc.) The point they’re making is that there’s no validation on the server side.  
If you create a form with a TextField max\_length of 50, and someone alters that field in their browser to allow for 500 characters - and sends 500 characters, your application is going to need to deal with a 500-character submission. (Or 500K, or 500M if the server will allow a POST that large.)

> [@Sammeeey](#):
>
> I am wondering "what is a large-sized string - 500, 1000, 10000 characters?

To some degree it depends upon the database and how Django builds the SQL to construct tables in that database.

For example, MariaDB defines a varchar as being up to 64K (65535) - [VARCHAR — MariaDB Documentation](https://mariadb.com/docs/reference/mdb/data-types/VARCHAR/)

On the other hand, PostgreSQL says that there’s no performace difference between `varchar(n)` and `text`, so for that it wouldn’t matter. (See the Note section at [PostgreSQL: Documentation: 14: 8.3.&nbsp;Character Types](https://www.postgresql.org/docs/14/datatype-character.html))
