PostgreSQL Error 23514: Check Violation

PostgreSQL error 23514 (Check Violation) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.

SQLSTATE 23514 PostgreSQL Last verified 2026-08-19

Quick Answer

Read the constraint name from the error detail. If that does not apply, inspect its definition with pg_get_constraintdef() to see the exact rule — the full checklist is below.

Error Code

SQLSTATE: 23514
Official name: Check Violation
Service: PostgreSQL

What does this error mean?

A CHECK constraint was violated because a row did not satisfy the constraint expression.

Common Causes

How to Fix

  1. Read the constraint name from the error detail
  2. Inspect its definition with pg_get_constraintdef() to see the exact rule
  3. Correct the offending value or relax the constraint if the rule is wrong
  4. Validate at the application layer first to give friendlier feedback

Code Examples

View a check constraint definition sql
SELECT conname, pg_get_constraintdef(oid)
FROM pg_constraint
WHERE contype = 'c' AND conrelid = 'products'::regclass;

Returns the human-readable CHECK expression so you can see exactly why the row was rejected.

Framework-Specific Fixes

django

Use validators on model fields to catch invalid data before it hits the DB CHECK.

from django.core.validators import MinValueValidator

class Product(models.Model):
    price = models.DecimalField(validators=[MinValueValidator(0)])
sqlalchemy

Add a CheckConstraint on the model; pair with a Python-side validator for nicer errors.

from sqlalchemy import CheckConstraint

class Product(Base):
    price = Column(Numeric, CheckConstraint('price >= 0'), nullable=False)

You Might Also Like

Frequently Asked Questions

Why am I seeing PostgreSQL error 23514?

Most often this happens when inserting a value outside an allowed range (e.g. negative price, age < 0), or when violating a domain or enum membership check.

How do I fix PostgreSQL error 23514?

Read the constraint name from the error detail.

Which frameworks have documented fixes for error 23514?

This page documents fixes for: django, sqlalchemy.

Official Sources

This page is based on the official PostgreSQL documentation linked below and adds practical troubleshooting guidance on top.