Why doesn't the generated client use the .env file specified by dotenv?
package.json
.env
.env.development
After executing
pnpm run migrate:dev
, Prisma correctly loads the .env.development
and creates tables in the t-prisma-test-dev
database. However, when I query data using the client, I encounter the following error: 'Database t-prisma-test
does not exist on the database server at localhost:3306
. Why is the client operating on the t-prisma-test
database specified in the .env
file?'1 Reply
Hi @ahcheng 👋
The environment variables used by Prisma Client are loaded from the
.env
file by default. While your migration script correctly uses the .env.development
file due to the dotenv command, the Prisma Client does not automatically do so. To resolve this issue, you need to ensure that the Prisma Client also uses the .env.development
file when you are working in a development environment.
One way to achieve this is by setting the DATABASE_URL
environment variable explicitly before running your application. You can modify your package.json scripts to include this: