← Back to Blog

Organize Your Prisma Schema into Multiple Files

Jon Harrell
Jon Harrell
June 4, 2024
Updated July 6, 2026

Prisma ORM lets you organize your Prisma Schema into multiple files. You split your models across as many .prisma files as you like, relations work across files without any imports, and Prisma combines everything when you run prisma generate or a migration command. The feature is Generally Available since v6.7.0, so no preview flag is needed. In Prisma ORM v7, you point the schema property in prisma.config.ts at the directory that holds your schema files. This post shows the setup, when to split, and the pitfalls to avoid.

Multi-file schemas were one of our most requested features: they first shipped as the prismaSchemaFolder Preview feature in v5.15 and went GA in v6.7.0.

How to split your Prisma Schema into multiple files

A multi-file schema keeps your main schema.prisma, containing the generator and datasource blocks, at the top of your prisma directory, with your models split into files alongside or below it. A common layout groups model files in a models subdirectory:

prisma/
├── migrations
├── models
│   ├── user.prisma
│   └── post.prisma
└── schema.prisma

In Prisma ORM v7, tell Prisma where your schema directory lives via the schema property in prisma.config.ts. Note that it points at the directory, not at a single file:

// prisma.config.ts
import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/",
  migrations: {
    path: "prisma/migrations",
  },
  datasource: {
    url: env("DATABASE_URL"),
  },
});

The main schema.prisma only carries the generator and datasource blocks (in v7, the connection URL lives in prisma.config.ts, as shown above):

// prisma/schema.prisma
generator client {
  provider = "prisma-client"
  output   = "../src/generated/prisma"
}

datasource db {
  provider = "postgresql"
}

If you need a PostgreSQL database for DATABASE_URL, the fastest way to get one is Prisma Postgres: running npm create db provisions a database and gives you the connection string to put in your .env file.

Now you can create model files in your schema directory. All models can be referenced in all files, so relations can cross files like so:

// prisma/models/user.prisma
model User {
  id    Int     @id @default(autoincrement())
  name  String
  posts Post[]
}
// prisma/models/post.prisma
model Post {
  id       Int     @id @default(autoincrement())
  title    String
  content  String
  authorId Int
  author   User    @relation(fields: [authorId], references: [id])
}

When running prisma generate, all schema files are combined, so your workflow continues as normal. Other Prisma CLI commands, such as validate and format, work with multi-file schemas too, and the Prisma VS Code extension understands them as well, including "Go to Definition" across files.

We verified this exact setup on Prisma ORM 7.8.0: prisma generate, prisma db push, and relation queries across the two files above all work without any flag.

Common pitfalls

A few things to watch out for, all of which we ran into while testing:

  • Point schema at the directory, not the file. If prisma.config.ts says schema: "prisma/schema.prisma", Prisma only reads that one file: prisma generate still succeeds, but the generated client silently contains none of the models from your other files. If your models seem to have disappeared after splitting files, check this first.
  • Keep schema.prisma directly in the configured directory. The file with your generator block must sit at the top of the directory you configured (e.g. prisma/schema.prisma), not in a subdirectory like prisma/models/.
  • Keep the migrations directory at the same level as schema.prisma.
  • Keep every .prisma file inside the configured directory. Prisma only loads files from the directory you specify, so files outside it are ignored.

When to use multi-file schemas

We've heard and seen that as a project grows, a single-file Prisma Schema eventually hits a point where it's simply too large to manage effectively. You'll see immediate benefits from this feature if you:

  • Have a complex schema: if your schema has large models or complex relations, putting related models into a separate file can help make your schema easier to understand and navigate.
  • Have a large team: when you have a single Prisma Schema file and have many developers committing, you could run into some pretty annoying merge conflicts during your day. Separating a large schema into several files can help reduce this pain.

Tips for multi-file Prisma Schemas

We've found 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.prisma while post-related models go in post.prisma. Try to avoid having "kitchen sink" schema files.
  • Use clear naming conventions: schema files should be named clearly and succinctly. Use names like user.prisma and post.prisma and not myModels.prisma or CommentFeaturesSchema.prisma.
  • Have an obvious "main" schema file: while you can have as many schema files as you want, you'll still need a place where you define the generator block. 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, and base.prisma are a few we've seen that work well.

Sample Project

If you'd like to see how this feature looks in the real world, check out our fork of dub from dub.co, one of our favorite OSS projects!

Looking ahead: Prisma Next

Schema organization is also central to Prisma Next, the next generation of Prisma ORM, available in Early Access today and becoming Prisma 8 at GA. In Prisma Next, your schema is a single centralised data contract that both you and your coding agent work against, and you can author it in Prisma Schema Language or in TypeScript, keeping your data model in the same language as your application.

It's fast, too: in our published benchmark, a fork of the open-source drizzle-benchmarks suite, Prisma Next reaches roughly 90% of the raw pg driver's speed and ships a client of about 148.5 KB gzipped. Like Prisma ORM, it pairs with Prisma Postgres out of the box. For new projects, especially ones built with AI coding agents, it's the direction to watch.

Where to go next

Keep reading

Build your next app with Prisma

Start free. Scale when you’re ready.

Try Prisma
Share this article