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:
1 | + | class CommentModel(models.Model): | |
2 | + | body = models.CharField(max_length=5000) |
Using TextField
for very long string fields would simplify the code and make is easier to maintain.
- | body = models.CharField(max_length=5000) |
+ | body = models.TextField() |
3 | + | date = models.DateField() |