Hello, I am running to an issue in my `schema.pris...
# prisma-data-platform
c
Hello, I am running to an issue in my
schema.prisma
file. So I configured my app to using data proxy provided, and used the the provided
prisma://....
as DATABASE_URL connection string in my
schema.prisma
file. However, When I tried migrating the models
npx prisma migrate dev
- I got this error:
Copy code
Error: Get config: Schema Parsing P1012
error: Error validating datasource `db`: the URL must start with the protocol `postgresql://` or `postgres://`.
--> schema.prisma:8
|
7 | provider = "postgresql"
8 | url = env("DATABASE_URL")
|
Validation Error Count: 1
How do I fix this?
a
Hey Chris 👋, Currently, you can’t use the Data Proxy connection string for running database migrations. You will need to use your original database connection string when running
prisma migrate
commands. You can read more here.
c
Hello @Austin, thanks for your response. I very much appreciate it. So are you saying that I’d have to switch back and forth between using my Data Proxy connection and my database connection string every time I run
prisma migrate
? I plugged in my database connection string and started my app, but got this error:
Copy code
error - InvalidDatasourceError: Datasource URL should use prisma:// protocol
a
Yes, we recommend setting up npm scripts to handle this switching for you:
Copy code
// package.json
{
  ...,
  "scripts": {
    "generate-client": "PRISMA_CLIENT_ENGINE_TYPE='dataproxy' prisma generate",
    "migrate": "DATABASE_URL=\"$MIGRATE_DATABASE_URL\" prisma migrate deploy",
    ...
  }
}
c
thank you @Austin, your response is very much appreciated
Hi @Austin, Thanks again for your response. So I followed your advice you gave the other day. After modifying my package.json and .env files, my code looks like this (below), but I still can’t start the app or run
npx prisma migrate dev
without switching the
DATABASE_URL
. Does this look right to you?
Copy code
//package.json

"scripts": {
            "dev": "next dev",
            "build": "next build",
            "start": "next start",
            "postinstall": "prisma generate",
            "lint": "next lint",
            "generate-client": "PRISMA_CLIENT_ENGINE_TYPE='dataproxy' prisma generate",
            "migrate": "DATABASE_URL=\"$MIGRATE_DATABASE_URL\" prisma migrate deploy"
      },
Copy code
//.env

MIGRATE_DATABASE_URL='<prisma://aws-us-east>-...'  //these are part of the strings
DATABASE_URL='<postgresql://mentorsuser>:Oluw...'  //these are part of the strings

PRISMA_CLIENT_ENGINE_TYPE=dataproxy
a
Hey Chris, you need to swap the environment variables around, the
MIGRATE_DATABASE_URL
needs to be your actual Postgres connection string, and the
DATABASE_URL
will be the Data Proxy connection string.
c
Thanks @Austin 🙏
🚀 1