P
Prisma6mo ago
Markigno

multi file schema

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?
4 Replies
Prisma AI Help
Prisma AI Help6mo ago
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
npx prisma generate --schema=./prisma
or, if your schema files are in prisma/schema:
npx prisma generate --schema=./prisma/schema
npx prisma generate --schema=./prisma/schema
Alternatively, you can set this in your package.json:
"prisma": {
"schema": "./prisma"
}
"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
prisma/
schema.prisma # contains generator and datasource
models/
user.prisma
post.prisma
Then run:
npx prisma generate --schema=./prisma
npx prisma generate --schema=./prisma
This should correctly combine all your models and generate the client as expected.
Source: Prisma Docs - Schema location
Nurul
Nurul6mo ago
Hey! Did the bot answer help?
Markigno
MarkignoOP6mo ago
@Nurul yes... it seems documentation is not updated regarding this topic...
Nurul
Nurul6mo ago
Was there a specific section you found missing in docs?

Did you find this page helpful?