简体   繁体   中英

Environment variables not registering in Prisma schema

I am finding the only way the Prisma schema can detect environment variables is to include a .env file in the root directory of its app.

I am using docker compose to build a few services, one of which is an app that manages a database using Prisma. The environmental variables is available in the app via process.env however Prisma can not detect this using the env function.

Here is how I am accessing the variable in schema.prisma :

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

And I am passing the variable in the docker compose in this way:

  app:
    build:
      context: ./app
    environment:
      DATABASE_URL: ${DATABASE_URL}

How can I make this function detect environment variables that don't necessarily belong to a .env variable?

I eventually worked this out. When I am running commands in my terminal I am running them outside of the docker container, So the prisma code running inside docker works perfect. but the commands I run outside can't see that.env file.

I was able to solve by adding the env values to my scripts. It may not be the most elegant solution but it works. For example:

eval $(grep '^DATABASE_URL' ../.env) prisma db pull && prisma generate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM