CharField with huge max_length

Using TextField for very long string fields would simplify the code and make is easier to maintain.

CharField should be used for smaller strings and TextField should be used for larger strings.

CharField max_length adds value when the value is known format (phone numbers, ISBN) with a known maximum valid length.

For arbitrary long text the max_length adds scope for unwanted validation errors without adding value elsewhere. Remove it and rely on unconstrained TextField.

If our GitHub code review bot spots this issue in your pull request it gives this advice:

django-doctorbotsuggested changes just now
models.py
1
+
class CommentModel(models.Model):
2
+
    body = models.CharField(max_length=5000)
Suggested changes
-
    body = models.CharField(max_length=5000)
+
    body = models.TextField()
Commit suggestion

Using TextField for very long string fields would simplify the code and make is easier to maintain.

Read more
3
+
    date = models.DateField()
Update models.py
We're your Django code review copilot. Get code improvements right in your pull request with our GitHub code review bot.

Configuring this check

Code Review Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code huge-max-length in your pyproject.toml file.

Read more about configuring Code Review Doctor.