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 we spot this issue in your GitHub pull request we give this advice:

models.pymaintainabilitylow
class CommentModel(models.Model):
-
    body = models.CharField(max_length=5000)
+
    body = models.TextField()
    date = models.DateField()

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

Read more
Protect your pull requests from over 40 types of common Django technical debts with our GitHub code review bot.

Configuring this check

Django 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 Django Doctor.