PostgreSQL error 22001 (String Data Right Truncation) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.
Check the column's defined length with \d table or information_schema. If that does not apply, widen the column with ALTER TABLE ... TYPE varchar(N) or use TEXT — the full checklist is below.
SQLSTATE: 22001
Official name: String Data Right Truncation
Service: PostgreSQL
A string value was too long for the column's character type and was truncated, which is not allowed.
ALTER TABLE profiles ALTER COLUMN name TYPE varchar(120);
Increasing the length limit is safe and online; truncating existing data would require a USING clause.
Use max_length on CharField; Django validates before sending oversized strings.
class Profile(models.Model):
name = models.CharField(max_length=50)
Set String(length=...) and validate length in Python.
name = Column(String(50))
Widen the column type in the Table Editor, or validate length before insert.
ALTER TABLE profiles ALTER COLUMN name TYPE varchar(120);
Most often this happens when inserting a value longer than varchar(N) or char(N), or when concatenated/derived strings exceeding the column width.
Check the column's defined length with \d table or information_schema.
This page documents fixes for: django, sqlalchemy, supabase.
Recommendations are editorial — DB Error Reference takes no payment or affiliate fees for tool listings.
This page is based on the official PostgreSQL documentation linked below and adds practical troubleshooting guidance on top.