Multiple prisma schemas with custom output directory throws errors on generate
Hi.
This is my codebase structure:
- prisma/schema.prisma (I have main config like db connection here)
- prisma/schema directory which contains multiple .prisma files
- i have output folder for prisma client in prisma/client
My problem is that the initial
prisma generate works but once it is generated I cannot run prisma generate again because it marks everything as duplicately defined. Is there a way to fix this?9 Replies
You opted for speed from this bot. Let's conjure up an answer right now!
Your issue is a common challenge when using multiple Prisma schema files and a custom output directory. The main problem is that when you run prisma generate, Prisma merges all .prisma files (if you use a setup like schema.prisma plus additional files in a subdirectory), which can lead to duplicate model or generator definitions if the files are not managed carefully.
Key points and solutions:
1. Duplicate Definitions: If you have multiple .prisma files that each define generators, datasources, or models with the same names, Prisma will throw errors about duplicate definitions on subsequent generates. This is expected behavior if the files are all included together and not properly separated or composed.
2. Recommended Structure: The typical approach for multiple schemas is to keep each schema in its own directory, with its own schema.prisma and output directory. For example:
Then, generate each client separately:
This avoids conflicts and duplicate definitions, as each schema is processed in isolation Multiple Connections / Databases / Datasources.
3. Custom Output Directory: If you use a shared output directory (e.g., prisma/client), ensure only one schema writes there, or you risk overwriting or conflicting files. Each schema should have its own output directory to prevent this.
4. Workarounds: If you want to compose schemas, you must ensure that only one generator and datasource block exists in the final composed schema, and that model names do not conflict. Otherwise, Prisma will error on generate Abnormal behavior of schema.prisma outside the main folder.
Summary:
To fix your issue, separate your schemas into dif ferent directories, each with its own output, and run generate for each schema individually. Avoid merging multiple generator or datasource blocks in a single generate run. If you need more advanced schema composition, Prisma currently does not natively support this without manual schema management.
To fix your issue, separate your schemas into dif ferent directories, each with its own output, and run generate for each schema individually. Avoid merging multiple generator or datasource blocks in a single generate run. If you need more advanced schema composition, Prisma currently does not natively support this without manual schema management.
This does not solve my issue. I still need to have one file that will have the config, either in root prisma folder or under schema folder and other schemas inside schema folder.
š¤ Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
I cannot share more of the code since it is under NDA but I had to create symlinks for
@prisma/client beecause it was getting called for no reason even though I use my generated prisma client references everywhere.
This is the error I have been getting.
I cannot provide any more details at the moment, I do not know if this is a Prisma bug or an issue on my end.
My current setup is:
package.json
Client output is set to following:
output = "../../generated/prisma-client"
And this script is being run at the end of Dockerfile@jacob Is you multiple .prisma files working?
It is locally, but I had to spend a lot of time making it work in Docker
I am not setting up it can you help me?
Create your own thread
Can you check if you are getting the error in latest prisma version - 6.11.0 as well?