#multi file schema

5 messages · Page 1 of 1 (latest)

dense wing
#

I'm creating a new project with new schema and i want to use multi-file approach.
I have the directory "prisma" where is add the file schema.prisma with this content
generator client {
provider = "prisma-client-js"
output = "../generated/prisma"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

now i have all the schemas inside the subdirectory "schema". When i run npx prisma generate it generate an empty schema without the models. what i'm doing wrong?

cosmic tundraBOT
#

You opted for speed from this bot. Let's conjure up an answer right now!

cosmic tundraBOT
# cosmic tundra You opted for speed from this bot. Let's conjure up an answer right now!

You're encountering this issue because, with the multi-file schema feature, you must point the Prisma CLI to the directory containing your schema files—not just the main schema.prisma file. When using a multi-file setup (e.g., with a prisma/schema subdirectory containing your model files), you need to run Prisma CLI commands with the --schema flag set to the directory, like this:

npx prisma generate --schema=./prisma

or, if your schema files are in prisma/schema:

npx prisma generate --schema=./prisma/schema

Alternatively, you can set this in your package.json:

"prisma": {
  "schema": "./prisma"
}

Key points:

  • The file with the generator and datasource blocks (e.g., schema.prisma) must be in the root of the directory you pass to --schema.
  • All your model files should be in the same directory or subdirectories.
  • If you just run npx prisma generate without specifying the directory, Prisma will only look at the single schema.prisma file and ignore the others, resulting in an empty schema.

For more details and examples, see the official documentation: Schema location & multi-file setup.

Tip: Make sure your directory structure looks like this:

prisma/
  schema.prisma   # contains generator and datasource
  models/
    user.prisma
    post.prisma

Then run:

npx prisma generate --schema=./prisma

This should correctly combine all your models and generate the client as expected.
Source: Prisma Docs - Schema location

light jasper
#

Hey!

Did the bot answer help?

dense wing
#

@light jasper yes... it seems documentation is not updated regarding this topic...