Prisma FAQ & Answers
100 expert Prisma answers researched from official documentation. Every answer cites authoritative sources you can verify.
Jump to section:
Getting Started > Initial Setup Methods
3 questions"postinstall": "prisma generate" in the scripts section. This ensures Prisma Client is regenerated at build time, solving caching issues on deployment platforms.
PrismaClient automatically connects lazily when you run your first query. It creates a connection pool at that time and disconnects when the Node.js process ends.
Models > Schema Organization
3 questionsPrisma looks for schemas in two default locations: ./prisma/schema.prisma and ./schema.prisma.
Organize your files by domain: group related models into the same file. For example, keep all user-related models in user.prisma while post-related models go in post.prisma.
When using a multi-file Prisma schema, you must always explicitly specify the location of the directory that contains your schema files (including the main schema.prisma file with your generator block) using --schema flag, package.json configuration, or prisma.config.ts.
What is Prisma ORM
3 questionsPrisma Studio currently supports PostgreSQL, MySQL, and SQLite. Support for CockroachDB and MongoDB is not currently available.
Neon Serverless, PlanetScale Serverless, and @libsql/client (for Turso) work with both Cloudflare Workers and Vercel Edge Functions. The node-postgres (pg) driver with Cloudflare's connect() only works with Cloudflare Workers, not Vercel Edge Functions.
As of Prisma ORM v7, the url, directUrl, and shadowDatabaseUrl fields in the Prisma schema datasource block are deprecated. These fields should be configured in Prisma Config instead.
Querying Data > Raw SQL Queries
2 questionsMongoDB raw query support ($runCommandRaw, findRaw, and aggregateRaw) was added in Prisma version 3.9.0.
Models > Field Definitions
2 questionsBy default, Prisma ORM's String type gets mapped to MySQL's varchar type.
When using scalar list filters with relational database connectors, array fields with a NULL value are not considered by conditions like NOT (array does not contain X) and isEmpty (array is empty).
CRUD Operations > Field Selection
2 questionsYes, you can nest select inside an include to have fine-grained control over which fields are returned from a relation. Example: include: { posts: { select: { title: true } } }
The omit feature was released into General Availability with Prisma ORM 6.2.0. It was previously available via the omitApi Preview feature in versions 5.13.0 through 6.1.0.
Models > Constraints and Validation
2 questionsIf you pass an empty update clause, the @updatedAt value will remain unchanged.
If you do not specify referential actions, Prisma ORM uses Restrict as the default for onDelete and Cascade as the default for onUpdate.
Prisma Client Setup > Client Configuration
2 questionsPrisma ORM v7 uses a TypeScript-based query compiler with WebAssembly by default, no longer depending on Rust native binaries. This enables use in environments that support JavaScript or WASM, such as Cloudflare Workers, Bun, and Deno.
For Prisma v6.19 and earlier with Rust-based engines, you can use library (default, uses Node-API) or binary (uses executable binary). In v6.16+, you can use client (Generally Available) to run without Rust binaries using driver adapters.
Data Model > Attributes & Modifiers
2 questionsEach model can have a maximum of one @id or @@id for a single- or multi-field primary key constraint per model.
The five referential actions are: Cascade (deletes/updates related records), Restrict (prevents operation if records are connected, not available on SQL Server), SetNull (sets fields to null), SetDefault (sets fields to default values, not supported on MySQL/MariaDB), and NoAction (database-specific behavior, may defer integrity checks).
Type Safety > Generated Types
2 questionsUserDefaultArgs is used with Prisma.validator to create type-safe objects for select or include operations, like: Prisma.validator<Prisma.UserDefaultArgs>()({ include: { posts: true } })
By default, Prisma Client is generated into the node_modules/.prisma/client folder. The actual types are stored in the .prisma/client folder, and @prisma/client/index.d.ts exports the contents of this folder.
Querying Data > CRUD Operations
2 questionsThe rejectOnNotFound parameter was deprecated in Prisma version 4.0.0.
Getting Started > Querying & Client Usage
2 questionsAdd the mode property with value 'insensitive' to the filter, for example: { email: { endsWith: 'prisma.io', mode: 'insensitive' } }
No, Prisma Client's distinct option does not use SQL SELECT DISTINCT. It was designed this way to support select and include as part of distinct queries.
Error Handling > Error Codes
2 questionsType Safety > Partial Model Structures
1 questionThe default selection set includes all scalar fields defined in the Prisma schema (including enums and arrays/scalar lists), but none of the relation fields. Relations are not included by default because they are not scalar fields.
Native Database Types > Text and String Types
1 questionYes. You can map String fields to PostgreSQL's UUID type using @db.Uuid, commonly with database-generated defaults like @default(dbgenerated('gen_random_uuid()'))
Working with JSON > Database-Specific Implementations
1 questionIn Prisma 5+, the path argument for PostgreSQL only accepts an array format, for example: path: ['someSetting'] or path: ['pet2', 'petName']
Referential Actions > Action Types
1 questionSets relation scalar fields to their default values on update or delete of relation.
Indexes > Full-Text Search Indexes
1 questionPostgreSQL supports 'and' (&) and 'or' (|) operators for combining search terms.
Data Sources > Migration and Development Database Settings
1 questionPrisma Migrate requires that the database user defined in your datasource has permission to create databases in order to automatically create and delete the shadow database.
Error Handling > Error Detection Patterns
1 questionIn the event of a Rust panic from the Prisma engine, the CLI exits the process with a non-successful exit code of 1. Previously, Prisma ended the process with a successful exit code of 0.
Indexes > Index Configuration Options
1 questionIf you introspect a database, the names for indexes and constraints will be added to your schema using the map argument unless they follow Prisma ORM's naming convention - if they do, the names are not rendered to keep the schema more readable.
Pagination > Pagination Parameters
1 questionNo, there are known issues where Prisma does not use LIMIT in the generated SQL for certain cursor-based pagination scenarios, which can cause performance issues and memory problems.
Querying Data > Filtering and Sorting
1 questionASC (ascending) order is the default when no sort direction is specified.
Models > Default Values and Auto-generation
1 questionStatic default values for DateTime are based on the ISO 8601 standard. Example: data DateTime @default("2020-03-19T14:21:00+02:00")
Prisma Client Setup > Client Extensions
1 questionUse Prisma.defineExtension() to make extensions shareable. This provides strict type checks and auto completion for both extension authors and users.
Performance Optimization > Query Optimization
1 questionMiddleware executes for every query, which means that overuse has the potential to negatively impact performance. To avoid adding performance overheads, check the params.model and params.action properties early in your middleware to avoid running logic unnecessarily.
Pagination > Sorting and Ordering
1 questionNo, case-insensitive sorting is not currently supported in orderBy. The 'mode' parameter (used for case-insensitive filtering) is not available for orderBy. Sorting case sensitivity is determined by database collation.
Prisma Pulse > Database Events
1 questionYes, Pulse will store the events that happen in your database in the same shape that they're delivered. This allows you to resume streams with zero data loss even when your server goes down.
Null and Undefined
1 questionPrisma recommends enabling the TypeScript compiler option exactOptionalPropertyTypes alongside strictUndefinedChecks, which will help catch cases of undefined values at compile time.
Models > Relations
1 questionNo. The @id attribute can only be defined on scalar fields (String, Int, enum), not on relation fields.
Prisma Schema > Attributes
1 questionIf you don't provide a value to the nanoid() function, the default value is 21. It accepts an integer value between 2 and 255 that specifies the length of the generated ID value.
Prisma Pulse > Core Concepts
1 questionNo, once the wal_level setting is changed to logical, it cannot be reverted.
Prisma Schema > Models and Fields
1 questionUse the @@id attribute with an array of field names at the model level. For example: @@id([firstName, lastName]) creates a composite primary key from both fields.
Native Database Types > JSON Types
1 questionFiltering on object key values within an array is only supported by the MySQL database connector. PostgreSQL does not support this feature.
Unsupported Types
1 questionUse the PostgreSQL cast operator ::text. For example: await prisma.$queryRawSELECT location::text FROM Country;``
Prisma CLI > Project Initialization
1 questionWhen run in Bun, the generated config does not include the import 'dotenv/config' line because Bun automatically loads .env files, whereas Node.js configurations include this import. The feature was introduced in Prisma ORM 7.2.0.
Transactions > Batch Operations
1 questionNo. Prisma does not offer a manual transaction rollback API. To rollback an interactive transaction, you must throw an error, which triggers automatic rollback.
Connection Pooling > External Pooling Solutions
1 questionNo. When you enable Accelerate and use the Accelerate connection string, your queries route through a connection pooler by default without the performance overhead of wrapping all queries in transactions.
Error Handling > Error Properties
1 questionWhen NODE_ENV is set to 'production', Prisma automatically uses the 'minimal' error format, which shows only the raw error message. This allows for easier digestion of logs in production environments.
Relation Modes > Referential Integrity Mechanisms
1 questionData Model > Enums & Types
1 questionPostgreSQL supports ALTER TYPE example_enum RENAME VALUE 'FOO' TO 'BAR' (added in Postgres 10), but Prisma doesn't currently use this method automatically. Instead, it generates an unsafe migration that creates a new enum type and attempts to convert existing data.
Prisma CLI > Migration Management
1 questionWhen there are migration history conflicts caused by modified or missing migrations, or when schema drift is detected (database schema has diverged from migration history). A migration that was already applied but later modified will trigger this prompt.
Getting Started > Quick Start Paths
1 questionThe Prisma ORM quickstart with Prisma Postgres takes 5 minutes to complete.
migrate deploy
1 questionEach migration in the _prisma_migrations table has a logs column that stores error messages when a migration fails. This can help with debugging failed migrations.
Composite Types > CRUD Operations
1 questionThe 'type' keyword is used in the Prisma schema to define composite types.
Raw Queries > Database-Specific Features
1 questionFull-Text Search > Query Operations
1 questionAfter adding @@fulltext to your schema, you must run prisma generate and either prisma db push or prisma migrate dev to update your database schema.
Querying Data > Aggregation and Grouping
1 questionYes, if you use skip and/or take with groupBy(), you must also include orderBy in the query.
Referential Actions > Enforcement Strategies
1 questionIn MySQL versions 8 and later, and MariaDB versions 10.5 and later, SetDefault effectively acts as an alias for NoAction.
Shadow Database
1 questionThe shadow database is a second, temporary database that is created and deleted automatically each time you run prisma migrate dev and is primarily used to detect problems such as schema drift or potential data loss of the generated migration.
Introspection > Schema Mapping & Translation
1 questionIf sanitization results in duplicate identifiers, no immediate error handling is in place. You get the error later when running prisma generate and must manually fix it by renaming one of the models.
Full-Text Search > Database-Specific Features
1 questionNo. In Prisma v6, full-text search was promoted to General Availability for MySQL. You can remove fullTextSearch from the previewFeatures in your Prisma schema if you use MySQL.
Prisma Accelerate > Connection Pooling
1 questionThe Prisma Accelerate connection pooler is available in 16 regions globally.
CRUD Operations > Relation Handling
1 questionFor relational databases, Prisma uses the foreignKeys relation mode by default, which enforces relations between records at the database level with foreign keys.
Prisma Client Setup > Driver Adapters
1 questionUsing engine type "client" requires either "adapter" or "accelerateUrl" to be provided to the PrismaClient constructor.
Relations > Relation Modes
1 questionIt is only possible to switch between relation modes when you use a relational database connector: PostgreSQL, MySQL, SQLite, SQL Server, or CockroachDB.
Referential Actions > Database Provider Rules
1 questionTransactions > Concurrency Control
1 questionThe entire transaction is rolled back. If the application encounters an error along the way, the async function will throw an exception and automatically rollback the transaction.
Relations > Relation Schema Definition
1 questionNo, the onDelete and onUpdate arguments must only be specified on the side of the relation that contains the foreign key (the side with the @relation attribute that has fields and references).
Upgrade Guides > Prisma 1 Migration
1 questionInstall the Prisma ORM versions 2.x and later CLI and run npx prisma init. Then connect to your database and introspect it with npx prisma db pull.
Fields & Types > Structured Data Types
1 questionIn Prisma 5, when filtering on JSON fields in a PostgreSQL model, the path argument now only accepts an array. The syntax must be path: ['someSetting'] instead of the Prisma 4 syntax path: 'someSetting'.
Database Providers > Connection Management
1 questionIn Prisma ORM v6, the default max_idle_connection_lifetime is 300 seconds (5 minutes). This is how long an idle connection can remain in the pool before being closed.
Multi-Schema Support > Configuration & Setup
1 questionNo. You can query models in multiple database schemas without any change to your Prisma Client query syntax.
Native Database Types > Numeric Types
1 questionNative database type attributes were introduced in Prisma version 2.17.0.
Getting Started > Framework Integration
1 questionNext.js's hot-reloading feature in development mode can create multiple instances of Prisma Client, which consumes resources and might cause unexpected behavior. The singleton pattern stores PrismaClient on globalThis in development, which persists across hot reloads, ensuring only one instance exists.
Relation Modes > Database Provider Compatibility
1 questionPrisma recommends using the 'prisma db push' command instead of 'prisma migrate' when making schema changes with PlanetScale.
Database Providers > NoSQL Database Providers
1 questionThe provider value must be "mongodb". Example: datasource db { provider = "mongodb" url = env("DATABASE_URL") }
Prisma Accelerate > Monitoring and Insights
1 questionPrisma Pulse > Database Setup
1 questionPrisma Migrate > Understanding Prisma Migrate
1 questionYou should edit migration SQL when: (1) renaming fields or tables to avoid data loss, (2) changing the direction of a 1-1 relation without data loss, (3) introducing significant refactors, or (4) adding features that cannot be represented in Prisma Schema Language such as partial indexes, stored procedures, views, or triggers.
Working with JSON > Reading and Writing Operations
1 questionPrisma.AnyNull represents both JSON null values and database NULL values, and can only be used when filtering (not for creating or updating data). It matches either type of null value in queries.
Performance Optimization > Performance Monitoring
1 question@opentelemetry/api became a peer dependency instead of a regular dependency. Users must install it separately with npm install @opentelemetry/api.
Composite Types > Composite Type Arrays
1 questionis requires one or more fields to be present, while equals requires all fields to be present. Use is for partial matching and equals for exact matching.
Querying Data > Relation Queries
1 questionNo, using only false values (e.g., select: { password: false }) will cause an error requiring at least one true field. Prisma recommends using the omit option instead to exclude specific fields.
Relations > Relation Troubleshooting
1 questionSetNull. This is the default when you don't explicitly specify onDelete in the @relation attribute.
Connection Pooling > Driver Adapters and Implementation
1 questionimport { PrismaMssql } from '@prisma/adapter-mssql'
const sqlConfig = {
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
server: process.env.HOST,
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000
},
options: {
encrypt: true,
trustServerCertificate: false
}
}
const adapter = new PrismaMssql(sqlConfig)
const prisma = new PrismaClient({ adapter })
migrate dev > Environment-Specific Behavior
1 questionNo. The --skip-generate and --skip-seed flags were removed in Prisma 7 because migrate dev no longer runs prisma generate or seeds automatically.
Database Connections > Connection Management Lifecycle
1 questionThe connection pool is created when Prisma Client opens the first connection to the database. This happens when the query engine is started, which occurs when the first Prisma Client query is invoked or when the $connect() method is called.
Views > Schema Definition & Configuration
1 questionYes. View fields support native database type attributes such as @db.VarChar(200) or @db.Text, which determine the specific native type in the database. These work the same way as they do for model fields.
Transactions > Isolation and Guarantees
1 questionYes. Operations are executed sequentially in the order they appear in the array. Prisma provides a dedicated transaction API which ensures these operations are executed in order and are guaranteed to either succeed or fail as a whole.
Introspection > Customization & Preservation
1 questionThe command is prisma db pull. It connects to your database and adds Prisma models to your Prisma schema that reflect the current database schema.
Prisma Schema > Data Sources
1 questionNo, 'datasource db' is just a convention. You can give your data source any name, for example, 'datasource mysql' or 'datasource data'.
Querying Data > Pagination
1 questionOffset pagination uses skip and take parameters. The skip parameter specifies how many records to skip, and take specifies how many records to return.
Relation Modes > Index Management
1 questionFebruary 16, 2024. Since then, you can alternatively use foreign key constraints at the database level in PlanetScale, which eliminates the need for setting relationMode = 'prisma'.