[Django]-Is there a need to set max_length in a model field?

2👍

You need to set it in CharField since it defaults to None, I believe. But there are some cases, like phone number, or ssn, or US State abbreviations where it will guide the user to type in a certain correct length of characters. According to the docs: https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.TextField

class TextField([**options])
A large text field. The default form widget for this field is a Textarea.

Changed in Django 1.7:
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 for that.

Leave a comment