PostgreSQL error: value too long for type character varying(255)

PostgreSQL·Sep 12, 2026·beginner·
Quick answer

You're trying to insert a string longer than the column's defined length limit. Either validate and truncate the input before saving, or increase the column's length limit — for genuinely long text (like article content), use `TEXT` instead of a length-limited `VARCHAR`.

What causes this error

VARCHAR(255) (or any specific length) enforces a hard character limit at the database level. If application code doesn't validate length before saving — or the limit was set too conservatively for real-world data — this error surfaces as a hard failure rather than silent truncation.

The Fix

-- If the field should genuinely have unlimited length (e.g. article content):
ALTER TABLE articles ALTER COLUMN content TYPE TEXT;

-- In Prisma schema, TEXT is what @db.Text maps to:
model Article {
  content String @db.Text
}

If there's a real reason for the limit (e.g. a username field), validate and give the user clear feedback client-side instead of letting the database reject it with a raw error.

Common causes / variations

  • Using the Prisma default String type (which maps to VARCHAR(191) or similar depending on provider) for a field that should be unlimited text
  • Pasting rich content (like this exact use case — long HTML article bodies) into a field that was never sized for it
  • Copy-pasting a schema convention from a different project with different length assumptions

Related errors

See also: syntax error at or near reserved keyword.

Was this fix helpful?

Comments

Loading comments...