DB migration does not work on Python Client with Prisma Postgres

I have created a project with prisma postgres for my python application. Following is an example prisma/schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

generator client {
provider = "prisma-client-py"
interface = "sync"
recursive_type_depth = 5
}

model Post {
id String @id @default(cuid())
created_at DateTime @default(now())
updated_at DateTime @updatedAt
title String
published Boolean
desc String?
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

generator client {
provider = "prisma-client-py"
interface = "sync"
recursive_type_depth = 5
}

model Post {
id String @id @default(cuid())
created_at DateTime @default(now())
updated_at DateTime @updatedAt
title String
published Boolean
desc String?
}
with the following .env
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=ey...
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=ey...
running prisma db push returns the following error
Error code: P1012
error: Error validating datasource `db`: the URL must start with the protocol `postgresql://` or `postgres://`.

To use a URL with protocol `prisma://`, you need to either enable Accelerate or the Data Proxy.
Enable Accelerate via `prisma generate --accelerate` or the Data Proxy via `prisma generate --data-proxy.`

More information about Data Proxy: https://pris.ly/d/data-proxy

--> prisma/schema.prisma:3
|
2 | provider = "postgresql"
3 | url = env("DATABASE_URL")
|

Validation Error Count: 1
[Context: getConfig]
Error code: P1012
error: Error validating datasource `db`: the URL must start with the protocol `postgresql://` or `postgres://`.

To use a URL with protocol `prisma://`, you need to either enable Accelerate or the Data Proxy.
Enable Accelerate via `prisma generate --accelerate` or the Data Proxy via `prisma generate --data-proxy.`

More information about Data Proxy: https://pris.ly/d/data-proxy

--> prisma/schema.prisma:3
|
2 | provider = "postgresql"
3 | url = env("DATABASE_URL")
|

Validation Error Count: 1
[Context: getConfig]
how to possibly solve this? The Docs have nothing of substance and no source to solve this issue. Or is there a way to get a direct URL for the same?
2 Replies
Prisma AI Help
Prisma AI Helpā€¢2w ago
You've gone full bot mode! Let me fetch that AI answer for you ASAP. I understand your issue with Prisma Postgres and migrations. This is a common problem when using Prisma Accelerate with the prisma+postgres:// protocol. The Problem The error you're seeing occurs because Prisma Migrate (which powers prisma db push) cannot work directly with the Prisma Accelerate connection string that starts with prisma+postgres://. Migrations need a direct connection to your database. The Solution You need to add a directUrl to your datasource configuration that points to your actual PostgreSQL database. This direct connection will be used for migrations while your Accelerate connection will be used for queries. 1. First, update your .env file to include a direct database connection:
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=ey..."
DIRECT_DATABASE_URL="postgresql://user:password@host:port/db_name?schema=public"
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=ey..."
DIRECT_DATABASE_URL="postgresql://user:password@host:port/db_name?schema=public"
2. Then modify your schema.prisma file to include the directUrl:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}
The directUrl should be your actual PostgreSQL connection string. This is required for migrations and introspection to work properly with Prisma Accelerate. This approach is documented in the Prisma Accelerate getting started guide, which explains:
Prisma Migrate and Introspection do not work with a prisma:// connection string. In order to continue using these features add a new variable to the .env file named DIRECT_DATABASE_URL whose value is the direct database connection string.
After making these changes, you should be able to run prisma db push successfully. If you don't have access to the direct database URL, you'll need to contact your database provider or the person who set up Prisma Accelerate for your project to obtain it. šŸ¤” 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.
Nurul
Nurulā€¢2w ago
Hey šŸ‘‹ Prisma Python Client is community maintained, so I am not 100% sure if Prisma Postgres would work with it. To confirm, you did try running npx prisma generate and the error still persists, right?

Did you find this page helpful?