I am getting this error message from prisma when I am running the GraphQL query.
Environment variable not found: DATABASE_URL.\n --> schema.prisma:6\n | \n 5 | provider = \"postgresql\"\n 6 | url = env(\"DATABASE_URL\")\n | \n\nValidation Error Count: 1",
At first, I didn't have the .env file in any of my project folders, then I added it with the link to the database url, still not working. Here is the folder structure:
This is what I have inside my .env
file looks like -
DATABASE_URL="postgres://postgres:[email protected]:5432/postgres"
One solution is to have multiple . env files which each represent different environments. In practice this means you create a file for each of your environments: .
The . env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can customize your environment variables as desired by modifying your . env file.
No do not commit environment variables. It needs to be added to the README.md Got it, also it should be on the root of the project, correct? Yep! Can you also create a .env in the prisma folder with just the DATABASE_URL? Can I update the README.md with this information and put in a PR? Or is there sensative information that we shouldn't use?
variables and fragments not defined properly. This is a typical error that you get when a client makes a request with a variable that has not been defined. A common nightmare when using GUI tools like GraphiQL where the variables UI has remnants of variable usage from previous queries.
No do not commit environment variables. It needs to be added to the README.md Got it, also it should be on the root of the project, correct? Yep! Can you also create a .env in the prisma folder with just the DATABASE_URL?
Read the source code for validation rules in graphql-js server to understand various query validation that goes through before executing the query. Do note that validation errors never return any data to the client, the execution errors have the ability to return partial data sets.
If anybody running into this issue, just run npx prisma generate
. This will re-establish the link between schema.prisma and .env file.
In my case I wanted to run Prisma Studio with NextJS that stores all environment variables in .env.local
, so I need to load the file first.
npm install -g dotenv-cli
dotenv -e .env.local -- npx prisma studio
Here is a link to the official Prisma docs on how to load .env
files manualy.
I had this issue in my NextJs project. after changing the .env.local file to .env everything worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With