I have a problem with schema.prisma data source, in which URL is supposed to be fetched from the environmental variable by line env("DATABASE_URL")
, but “Error validating datasource
db: the URL must start with the protocol 'mysql://'.
” is thrown instead.
I have set DATABASE_URL in the deployment options on app.netlify to value "mysql://LOGIN:PASSWORD@HOST/DB_NAME?sslaccept=strict"
(including the "). This value is 100% correct because if I paste it directly, it works fine. Moreover, the following code fixes my issue:
const client = globalThis.prisma || new PrismaClient({ datasources: { db: { url: process.env._DATABASE_URL.substring(1, process.env.DATABASE_URL.length - 1) } } });
In the function logs, I can see:
prisma:tryLoadEnv Environment variables not found at /var/task/node_modules/.prisma/client/..\..\..\.env
prisma:tryLoadEnv Environment variables not found at /var/task/node_modules/.prisma/client/..\..\..\.env
prisma:tryLoadEnv No Environment variables loaded
Clearly, prisma is not detecting environmental variables in its env function. How can I fix this problem?