Prisma CLI commands with the Data Proxy

Currently, you can only use Prisma Client with the Data Proxy to query your database.

When using Prisma CLI, you need a direct (non-Data Proxy) database connection if you apply schema changes to your database with Prisma Migrate or db push, or if you introspect your database. See Prisma CLI commands that require a direct database connection.

In Prisma versions 4.10.0 and later, you can set a direct database connection URL in your Prisma schema.

In earlier versions, you must add an environment variable with the direct database connection URL and overwrite the DATABASE_URL environment variable when you need a direct connection.

Prisma CLI commands that require a direct database connection

The following Prisma CLI commands require a direct connection:

  • prisma db pull
  • prisma migrate deploy
  • prisma migrate dev
  • prisma migrate diff (some parameters only)
  • prisma migrate reset
  • prisma migrate resolve
  • prisma migrate status
  • prisma db push
  • prisma db drop
  • prisma db execute
  • prisma studio

Set a direct database connection URL in your Prisma schema

To provide a URL for a direct database connection, set the directUrl property in the datasource block of your Prisma schema:

schema.prisma
1generator client {
2 provider = "prisma-client-js"
3}
4
5datasource db {
6 provider = "postgresql"
7 url = env("DATABASE_URL")
+ directUrl = env("DIRECT_URL")
9}

prisma studio currently doesn't support the directUrl property.

Then add the DIRECT_URL environment variable to your .env file:

.env
1# Connection to Prisma Data Proxy. Used by Prisma Client.
2DATABASE_URL="prisma://__HOST__/?api_key=__KEY__"
3
+# Connection to the database. Used for migrations and introspection.
+DIRECT_URL="postgresql://__USER__:__PASSWORD__@__HOST__:__PORT__/__DATABASE__"
Edit this page on GitHub