Skip to content
>devspeak
← glossary
level 4Databases

Constraint

also: constraints, unique constraint, check constraint, constraint violation

A rule the database enforces on your data, like "every user needs an email" or "no two users can share one". Data that breaks the rule is rejected.

a bit more technical

A rule defined in the schema and enforced by the database on every write: NOT NULL, UNIQUE, CHECK, PRIMARY KEY and FOREIGN KEY. A write that violates it fails with an error, no matter what the app code intended.

picture it

A parking garage barrier set to a height limit. It doesn't matter who's driving or what the app said. A vehicle that's too tall doesn't get in.

why it matters

Constraints are your last line of defense against bad data, even when the app code has bugs. When an agent hits a constraint error, the right fix is usually in the data or the code, not removing the rule.

what your agent might say
agent
Signup failed with a unique constraint violation on users.email. That address is already registered, so I'll show a friendly error instead of crashing.
how you might use it
you → your agent
Don't remove the constraint to make this error go away. Find out which data or code is breaking the rule and explain it to me.
common mistake

Thinking the constraint is the bug. Usually it's correctly catching a real problem somewhere else.

builds on