P
Prisma2mo ago
laurence

Error validating datasource `db`: the URL must start with the protocol `prisma://` or `prisma+postgr

Attempting to run e2e tests in a docker environment against a standalone nextjs server container. I use prisma accelerate in production, but for tests these will run in a server environment - so accelerate is not desired. I am working on a dynamic build and runtime that allows for dynamically using accelerate depending on the environment, but for debugging this issue I've simplified things and I've removed prisma accelerate completely from this branch to try and isolate the cause of this issue. This error is appearing in both 'test' and 'development' environments, also from Cypress runtime. But the db url is valid, the db is up, and I'm not using accelerate, i'm generating with --no-engine=false. So I don't understand why prisma is trying to use accelerate. Is there some way to have prisma print out why it's attempting to look for an accelerate url? error log
Using database URL for tests: postgresql://***:***@localhost:15432/foodguessr-test
prisma:error
Invalid `prisma.dailyGuess.deleteMany()` invocation:


Error validating datasource `db`: the URL must start with the protocol `prisma://` or `prisma+postgres://`
Database reset error: PrismaClientKnownRequestError:
Invalid `prisma.dailyGuess.deleteMany()` invocation:


Error validating datasource `db`: the URL must start with the protocol `prisma://` or `prisma+postgres://`
Using database URL for tests: postgresql://***:***@localhost:15432/foodguessr-test
prisma:error
Invalid `prisma.dailyGuess.deleteMany()` invocation:


Error validating datasource `db`: the URL must start with the protocol `prisma://` or `prisma+postgres://`
Database reset error: PrismaClientKnownRequestError:
Invalid `prisma.dailyGuess.deleteMany()` invocation:


Error validating datasource `db`: the URL must start with the protocol `prisma://` or `prisma+postgres://`
schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [pg_trgm, unaccent]
}

generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [pg_trgm, unaccent]
}

generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
}
* continued in comments
5 Replies
Prisma AI Help
Prisma AI Help2mo ago
You chose to compile with the bot. One moment while I piece together your answer…
laurence
laurenceOP2mo ago
prisma client
import { PrismaClient } from "@prisma/client";
import { env } from "~/lib/env";

const prismaClientSingleton = () => {
return new PrismaClient({
log:
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
});
};

type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;

const globalForPrisma = globalThis as unknown as {
prisma: PrismaClientSingleton | undefined;
};

const prisma = globalForPrisma.prisma ?? prismaClientSingleton();

export const db = prisma;

if (env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
import { PrismaClient } from "@prisma/client";
import { env } from "~/lib/env";

const prismaClientSingleton = () => {
return new PrismaClient({
log:
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
});
};

type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;

const globalForPrisma = globalThis as unknown as {
prisma: PrismaClientSingleton | undefined;
};

const prisma = globalForPrisma.prisma ?? prismaClientSingleton();

export const db = prisma;

if (env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
prisma generate
> p prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema

✔ Generated Prisma Client (v6.12.0, engine=none) to ./node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client in 72ms
> p prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema

✔ Generated Prisma Client (v6.12.0, engine=none) to ./node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client in 72ms
Test output (Cypress)
Using database URL for tests: postgresql://***:***@localhost:15432/app-test
prisma:error
Invalid `prisma.product.deleteMany()` invocation:


Error validating datasource `db`: the URL must start with the protocol `prisma://` or `prisma+postgres://`
Database reset error: PrismaClientKnownRequestError:
Invalid `prisma.product.deleteMany()` invocation:


Error validating datasource `db`: the URL must start with the protocol `prisma://` or `prisma+postgres://`
Using database URL for tests: postgresql://***:***@localhost:15432/app-test
prisma:error
Invalid `prisma.product.deleteMany()` invocation:


Error validating datasource `db`: the URL must start with the protocol `prisma://` or `prisma+postgres://`
Database reset error: PrismaClientKnownRequestError:
Invalid `prisma.product.deleteMany()` invocation:


Error validating datasource `db`: the URL must start with the protocol `prisma://` or `prisma+postgres://`
Prisma AI Help
Prisma AI Help2mo ago
Based on the information in your question and the provided knowledge sources, the error:
Error validating datasource `db`: the URL must start with the protocol `prisma://` or `prisma+postgres://`
Error validating datasource `db`: the URL must start with the protocol `prisma://` or `prisma+postgres://`
typically occurs when Prisma expects a connection string for Accelerate or Data Proxy, but receives a standard PostgreSQL URL instead. This can happen if: - You generated Prisma Client with the --no-engine flag, which tells Prisma to assume Accelerate/Data Proxy usage, even if your DATABASE_URL is a direct connection string. This is confirmed in multiple sources: using --no-engine in non-Accelerate environments causes Prisma to expect a prisma:// or prisma+postgres:// URL, leading to this error if you provide a postgresql:// URL instead. Removing --no-engine resolves the issue for direct database connections see discussion and issues here and here. - The generated Prisma Client is not compatible with your intended environment. If you previously generated the client with --no-engine or for Accelerate, you must re-generate it without that flag for local/dev/test environments. How to debug and resolve: 1. Ensure you are running npx prisma generate without --no-engine for your test/dev environment. 2. Delete your node_modules and the generated @prisma/client, then re-run npx prisma generate. 3. Double-check that your DATABASE_URL is set to a standard postgresql://... value in your environment. There is no built-in Prisma command to print why it expects an Accelerate/Data Proxy URL, but the behavior is directly tied to how you generate the client and which flags you use source. Summary:
Remove --no-engine from your generate command, re-generate the client, and ensure your DATABASE_URL is correct. This should resolve the error in your test and development environments. 🤔 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.
laurence
laurenceOP2mo ago
Why is (engine=none) being set here?
> p prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema

✔ Generated Prisma Client (v6.12.0, engine=none) to ./node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client in 72ms
> p prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema

✔ Generated Prisma Client (v6.12.0, engine=none) to ./node_modules/.pnpm/@prisma+client@6.12.0_prisma@6.12.0_typescript@5.8.3__typescript@5.8.3/node_modules/@prisma/client in 72ms
Turns out my development .env file was getting pulled into the build, and included:
PRISMA_GENERATE_NO_ENGINE="true"
PRISMA_GENERATE_NO_ENGINE="true"
I had recently pulled the prod variables from vercel to put in my .env, and within them all that flag env var was being set. I had no idea it was there. I didn't even think this .env was being used because I have a test .env file that I'm passing to the run command. But since it is a field I didn't have assigned in the test .env it picked it up from the development one. Would be great if there was a message about why engine was getting set to none, that would have saved me a full day of debugging 😅
Nurul
Nurul2mo ago
I am glad to hear that you were able to resolve this 🙌 There is this related GitHub Issue about a similar error: https://github.com/prisma/prisma/issues/21902
GitHub
"Error validating datasource db: the URL must start with the prot...
Bug description I have a monorepo with node.js micro services, each using their own database and prisma instance. I want to generate each prisma client without engines and let them use the engines ...

Did you find this page helpful?