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