As of 2023, it's not possible:
Check constraints are currently not included in the generated Prisma schema - however, the underlying database still enforces the constraints. https://www.prisma.io/docs/guides/other/advanced-database-tasks/data-validation/postgresql#2-adding-a-table-with-a-single-check-constraint-on-a-single-column
You'll have to create a custom migration: https://www.prisma.io/docs/guides/migrate/developing-with-prisma-migrate/customizing-migrations
Open issue to support CHECK: https://github.com/prisma/prisma/issues/3388
Prisma
prisma.io › home › check constraints › check constraints › check constraints › check constraints › check constraints
Data validation with CHECK constraints (PostgreSQL) | Prisma Documentation
A check constraint is a condition that must be satisfied before a value can be saved to a table - for example, the discounted price of a product must always be less than the original price.
Support SQL Check constraints
Right now we have no way of expressing SQL check constraints in our schema. We need a spec for this that we can implement in the future. More on github.com
Best practice for adding a check constraint in PostgresSQL?
If I use npx prisma migrate dev to generate the raw SQL migrations, but I want to add a custom check constraint as well, is it better to: Simply add the constraint to the bottom of the auto-generat... More on github.com
Do I need to check if a user is already in Postgresql db with prisma before adding them?
Depends on whether you have a unique constraint on for example the email address. If so, the db will throw an error on creation that you can catch. Otherwise it will just insert the duplicate. More on reddit.com
Enforce constraints on `Json` data (via JSON Schema and/or Check Constraints)
Problem The Json field is great for when you have data that might have a different schema, but the only problem so far is that you can't enforce any constraint on this data. Currently, MySQL ha... More on github.com
08:02
Unique Constraints | Express API & Prisma ORM Query Fundamentals ...
45:55
Complex Schema Design with Drizzle ORM | Common Patterns - YouTube
Prisma Crash Course - Parte 08 - Relacionamento many-to-one
Prisma ORM Tutorial Under 30 Minutes
33:26
Prisma & PlanetScale Best Practices - YouTube
01:16:14
What's new in Prisma (v3.0.1) - YouTube
GitHub
github.com › prisma › prisma › issues › 3388
Support SQL Check constraints · Issue #3388 · prisma/prisma
December 3, 2019 - Right now we have no way of expressing SQL check constraints in our schema. We need a spec for this that we can implement in the future.
Author prisma
Prisma
prisma.io › dataguide › postgresql › column-and-table-constraints
PostgreSQL Constraints: column and table | Prisma's Data Guide
If we still want to make sure we don't end up with duplicate entries while allowing for repeated values in individual columns, a unique check on the combination of country and capital would suffice: ... DETAIL: Key (country, capital)=(Bolivia, Sucre) already exists. ... If you are using Prisma, you can define a unique field in your Prisma schema. Prisma is an open-source database toolkit for Typescript and Node.js that aims to make app developers more productive and confident when working with databases. The PRIMARY KEY constraint serves a special purpose.
Tericcabrel
blog.tericcabrel.com › database-integrity-prisma-orm
Emulate database integrity constraints using the Prisma ORM
June 5, 2023 - To fix the issue, The Prisma engine has a built-in feature to handle integrity constraints at the application level. This means the database schema will not have the foreign keys constraint, and Prisma will manage it. If you want to create a task with a user ID that doesn't exists in the users' table, Prisma will check it and throw an error.
PlanetScale
planetscale.com › docs › vitess › tutorials › prisma-best-practices
Prisma best practices - PlanetScale
March 30, 2026 - If you do not add the index, you ... of data. When you run prisma format or prisma validate, it will warn you about a missing index where you are using foreign key constraints. If you want to learn more about MySQL indexes, check out the MySQL for Developers course section ...
Reddit
reddit.com › r/node › do i need to check if a user is already in postgresql db with prisma before adding them?
r/node on Reddit: Do I need to check if a user is already in Postgresql db with prisma before adding them?
September 25, 2021 -
Should I do something like prisma.user.findUnique() before doing prisma.user.create() ? Or is the db smart enough to detect duplicates?
Top answer 1 of 5
14
Depends on whether you have a unique constraint on for example the email address. If so, the db will throw an error on creation that you can catch. Otherwise it will just insert the duplicate.
2 of 5
1
I think you want to use upsert for this. See the docs: https://www.prisma.io/docs/concepts/components/prisma-client/crud#update-or-create-records In other ORMs it's often called "findOrCreate" or similar
GitHub
github.com › prisma › prisma › issues › 16654
Enforce constraints on `Json` data (via JSON Schema and/or Check Constraints) · Issue #16654 · prisma/prisma
December 6, 2022 - The Json field is great for when you have data that might have a different schema, but the only problem so far is that you can't enforce any constraint on this data. Currently, MySQL has a native way of enforcing this with CHECK(JSON_SCHEMA_VALID(), _) function at table.
Author prisma
GitHub
github.com › prisma › prisma › issues › 17319
Add one-of-two not null constraint (via check constraint) · Issue #17319 · prisma/prisma
January 14, 2023 - constraint chk_price check (brandId is not null or retailerId is not null) Similarly to the @@unique multi-column constraint support that Prisma has, it'd be cool to have something like: @@notnull([brandId, retailerId]) which will ensure that ...
Author prisma
Drizzle ORM
orm.drizzle.team › docs › indexes-constraints
Drizzle ORM - Indexes & Constraints
CREATE TABLE "user" ( "id" integer ... integer CONSTRAINT "custom_name" UNIQUE NULLS NOT DISTINCT ); The CHECK constraint is used to limit the value range that can be placed in a column....
ZenStack
zenstack.dev › blog › custom-attributes
How to Add Custom Attributes in Prisma | ZenStack
February 9, 2023 - https://github.com/prisma/prisma/issues/3102 · Also, the below-related issues: Support SQL Check constraints #3388 · Add exclude in the query arguments #5042 · Support adding prefix to an @id field #3391 · In the following content, I will show you two ways of adding custom attributes: Comments workaround by Prisma (You can skip this part if you already know) Custom attributes of ZenStack.
Twitter
twitter.com › prisma › status › 1646126571072245760
Prisma — ORM. And Postgres too.
Prisma — ORM. And Postgres too.