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
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
Source: Prisma Docs - Schema location
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:
or, if your schema files are in prisma/schema:
Alternatively, you can set this in your package.json:
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:
Then run:
This should correctly combine all your models and generate the client as expected.Source: Prisma Docs - Schema location
Hey!
Did the bot answer help?
@Nurul yes... it seems documentation is not updated regarding this topic...
Was there a specific section you found missing in docs?