InvalidDatasourceError: Datasource URL should use prisma:// protocol

See original GitHub issue

I’m using prisma in nextjs, and the env urls start with postgres://. I’m working in a gitpod container. When I run next dev or build for production and run next start, I receive this error:

InvalidDatasourceError: Datasource URL should use prisma:// protocol

If I change my urls to start with prisma://, I get:

InvalidDatasourceError: No valid API key found in the datasource URL

Any ideas? Help would be much appreciated! I’ve listed my schema and versions of prisma below.

datasource db {
  provider             = "postgresql"
  url                  = env("DATABASE_URL")
  shadowDatabaseUrl    = env("DATABASE_MIGRATE_URL")
  referentialIntegrity = "prisma"
}

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["dataproxy", "referentialIntegrity"]
}

model User {
  id           Int            @id @default(autoincrement())
  WishlistItem WishlistItem[]
}

model Product {
  id           Int            @id @default(autoincrement())
  name         String
  price        Int
  salePrice    Int            @default(0)
  imageUrl     String
  flag         String?
  description  String?
  buyUrl       String
  marketplace  String?
  WishlistItem WishlistItem[]
}

model WishlistItem {
  id        Int     @id @default(autoincrement())
  userId    Int
  productId Int
  Product   Product @relation(fields: [productId], references: [id])
  User      User    @relation(fields: [userId], references: [id])
}

    "@prisma/client": "^3.8.1",
    "prisma": "3.8.1",
    "next": "12.0.8",
export const getServerSideProps = async ({}) => {
  const prisma = new PrismaClient()
  const products = await prisma.product.findMany()
  return { props: { products } }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jacobhqcommented, Feb 27, 2022

TLDR: I solved this by removing dataproxy from the previewFeatures part of my schema.

@Zineeddine998 Prisma has a feature called Data Proxy, a tool for db connection management in serverless environments (better explained in this blog post from prisma), which I was not using for this project, but had enabled it as I copied code from a previous project that was. As you can see below, it was ledt enabled.

previewFeatures = ["dataproxy", "referentialIntegrity"]

When using Data Proxy, you are given a proxy url starting with the prisma:// protocol. The url in my env var started with the postgres:// protocol, and were therefore not accepted. I was unable to deduce this from the error message, and opened the issue, and @janpio’s comment helped me realise. I then solved this by removing dataproxy from the previewFeatures part of my schema.

1reaction
jacobhqcommented, Feb 2, 2022

Thanks for pointing that out! This is not a bug it’s just the fact that I wasn’t using the dataproxy. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

InvalidDatasourceError: Datasource URL should use prisma ...
Not happy with the AWS service I am now switching my database to railway.app - which is working out well for me. However,...
Read more >
(Solved) The URL for datasource `DS` must start with the ...
My schema.prisma file says: datasource DS { provider = ["sqlite", "postgresql"] url = env("DATABASE_URL") }.
Read more >
Connection URLs (Reference) - Prisma
Learn about the format and syntax Prisma uses for defining database connection URLs for PostgreSQL, MySQL and SQLite.
Read more >
Data Proxy - Prisma
Data Proxy in the Prisma Data Platform provides database connection management and pooling, load balancing, scaling, and fault tolerance features so that ...
Read more >
PostgreSQL database connector (Reference) - Prisma
This page explains how Prisma can connect to a PostgreSQL database using the PostgreSQL ... provider : Specifies the postgresql data source connector....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found