Using prisma with two different databases.
I have a NextJS project using Prisma ORM with Microsoft SQL Server. I am trying to setup Prisma to work with two different SQL Server databases in the same project. I cannot seem to get it working. I keep getting an error: TypeError: The "path" argument must be of type string. Recieved undefined. Anyone have any idea?
8 Replies
Skipping coffee for instant knowledge! Let's brew that AI answer now.
Currently I'm using two different prisma folders, I've also tried under the same prisma folder. Always getting the same error.

I can help you with setting up Prisma to work with two different SQL Server databases in your NextJS project.
The error you're encountering ("The 'path' argument must be of type string. Received undefined") is a common issue when working with multiple Prisma schemas. This typically happens when Prisma can't find the schema file path correctly.
Here's how you can set up multiple databases with Prisma:
1. Create separate schema files
Create two separate schema files for each database:
In each schema file, define the datasource and specify a custom output path for the generated client:
For
prisma/db-1/schema.prisma
:
For prisma/db-2/schema.prisma
:
2. Set up environment variables
In your .env
file:
3. Generate clients and run migrations
For the error you're encountering, make sure to use the full path to your schema files when running Prisma commands:
If you're using a package manager like pnpm, make sure to use the pac
kage manager's command:
4. Use the clients in your code
5. Add helper scripts
To simplify your workflow, add helper scripts to your package.json
:
This approach is based on the official Prisma documentation and community solutions for working with multiple databases Multiple Databases Guide and GitHub Discussion #24247.How should I properly export my clients to use the prisma clients throughout my application
🤔 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've tried implementing and still getting same error
I've tried both:
and
`
Do you get this same error if you only use one PrismaClient?
I am trying to understand if the error you are observing is caused due to multiple PrismaClients or something else