ORM Lens

DOL015 — TextField with max_length has no DB effect

Default severity: hint · Applicability: suggestion · Category: model

Detects max_length= on a TextField(...). TextField maps to TEXT/CLOB; Django only enforces its max_length in the auto-generated form widget, never at the database level. The kwarg therefore reads like a hard limit but is not one — raw ORM writes, bulk operations, and the admin’s direct saves can all exceed it. If you need a database-enforced limit, use CharField(max_length=...); if the text is genuinely unbounded, drop the kwarg. The QuickFix (“Remove max_length from TextField”) strips the kwarg; it is a suggestion because you may instead want the CharField conversion.

Bad

class Comment(models.Model):
    body = models.TextField(max_length=500)

Good

class Comment(models.Model):
    body = models.TextField()

Or, when the limit must hold at the DB level:

    body = models.CharField(max_length=500)

Suppress

# orm-lens-disable-next-line DOL015

Suppress if you intentionally use max_length purely as a form-layer cap. Or per-workspace in .vscode/settings.json: {"djangoOrmLens.rules": {"DOL015": "off"}}.