Schema location
The default name for the Prisma Schema is a single file schema.prisma in your prisma folder. When your schema is named like this, the Prisma CLI will detect it automatically.
Prisma Schema location
The Prisma CLI looks for the Prisma Schema in the following locations, in the following order:
-
The location specified by the
--schemaflag, which is available when youintrospect,generate,migrate, andstudio:prisma generate --schema=./alternative/schema.prisma -
The location specified in the
package.jsonfile (version 2.7.0 and later):"prisma": {
"schema": "db/schema.prisma"
} -
Default locations:
./prisma/schema.prisma./schema.prisma
The Prisma CLI outputs the path of the schema that will be used. The following example shows the terminal output for prisma db pull:
Environment variables loaded from .env
Prisma Schema loaded from prisma/schema.prisma
Introspecting based on datasource defined in prisma/schema.prisma …
✔ Introspected 4 models and wrote them into prisma/schema.prisma in 239ms
Run prisma generate to generate Prisma Client.
Multi-file Prisma schema
If you prefer splitting your Prisma schema into multiple files, you can have a setup that looks as follows:
.
├── migrations
├── models
│ ├── posts.prisma
│ ├── users.prisma
│ └── ... other `.prisma` files
└── schema.prisma
Multi-file Prisma schemas are Generally Available since v6.7.0. Before that, they could be used via the prismaSchemaFolder Preview feature flag.
Usage
When using a multi-file Prisma schema, you must always explicitly specify the location of the directory that contains the .prisma file with your datasource block.
You can do this in either of three ways:
-
pass the the
--schemaoption to your Prisma CLI command (e.g.prisma migrate dev --schema ./prisma) -
set the
prisma.schemafield inpackage.json:// package.json
{
"prisma": {
"schema": "./prisma"
}
} -
set the
schemaproperty inprisma.config.ts:import path from 'node:path'
import type { PrismaConfig } from 'prisma'
export default {
schema: path.join('prisma'),
} satisfies PrismaConfignoteWe recommend using the Prisma Config file to specify the location of your Prisma schema. This is the most flexible way to specify the location of your Prisma schema alongside other configuration options.
All examples above assume that your datasource block is defined in a .prisma file inside the prisma directory.
You also must place the migrations directory next to the .prisma file that defines the datasource block.
For example, assuming schema.prisma defines the datasource, here's how how need to place the migrations folder:
# `migrations` and `schema.prisma` must be on the same level
.
├── migrations
├── models
│ ├── posts.prisma
│ └── users.prisma
└── schema.prisma
Tips for multi-file Prisma Schema
We've found that a few patterns work well with this feature and will help you get the most out of it:
- Organize your files by domain: group related models into the same file. For example, keep all user-related models in
user.prismawhile post-related models go inpost.prisma. - Use clear naming conventions: schema files should be named clearly and succinctly. Use names like
user.prismaandpost.prismaand notmyModels.prismaorCommentFeaturesSchema.prisma. - Have an obvious "main" schema file: while you can now have as many schema files as you want, you'll still need a place where you define
datasourceandgeneratorblocks. We recommend having a single schema file that's obviously the "main" file so that these blocks are easy to find.main.prisma,schema.prisma, andbase.prismaare a few we've seen that work well.
Examples
Our fork of dub by dub.co is a great example of a real world project adapted to use a multi-file Prisma Schema.