Python

Python

Made by DeepSource

Consider using TextField instead of CharField PTC-W0904

Anti-pattern
Major
Autofix

CharField highlighted in the issue has a max_length > 256. It is recommended to use TextField for such long fields. CharField should only be used for smaller strings.

Reasons to fix this:

  • More readable and maintainable. Any developer reading the code in the future doesn't have to wonder about the specific max_length.
  • If for some reason, the current max_length needs to be increased, you'd need to create a new database migration to facilitate this change.

Not Preferred:

class MyModel(models.Model):
    my_field = models.CharField(max_length=1000)

Preffered:

class MyModel(models.Model):
    my_field = models.TextField()