Prisma CLI reference

This document describes the Prisma CLI commands, arguments, and options.

Installation

The Prisma CLI is typically installed locally as a development dependency, that's why the --save-dev (npm) and --dev (Yarn) options are used in the commands below.

We recommend that you install the Prisma CLI locally in your project's package.json to avoid version conflicts that can happen with a global installation.

npm

Install with npm:

npm install prisma --save-dev

Yarn

Install with yarn:

yarn add prisma --save-dev

pnpm

Install with pnpm:

pnpm install prisma --save-dev
  • npm

Install with npm:

npm install -g prisma
  • Yarn

Install with Yarn:

yarn global add prisma
  • pnpm

Install with pnpm:

pnpm install prisma --global

Usage

If you installed Prisma as a development dependency, you need to prefix the prisma command with your package runner.

npm

npx prisma

Yarn

yarn prisma

pnpm

pnpm dlx prisma

Synopsis

The prisma command can be called from command line once installed. When called without arguments, it will display its command usage and help document:

$prisma
Hide CLI results
Prisma is a modern DB toolkit to query, migrate and model your database (https://www.prisma.io)
Usage
$ prisma [command]
Commands
init Setup Prisma for your app
generate Generate artifacts (e.g. Prisma Client)
db Manage your database schema and lifecycle
migrate Migrate your database
studio Browse your data with Prisma Studio
validate Validate your Prisma schema
format Format your Prisma schema
Flags
--preview-feature Run Preview Prisma commands
Examples
Setup a new Prisma project
$ prisma init
Generate artifacts (e.g. Prisma Client)
$ prisma generate
Browse your data
$ prisma studio
Create migrations from your Prisma schema, apply them to the database, generate artifacts (e.g. Prisma Client)
$ prisma migrate dev
Pull the schema from an existing database, updating the Prisma schema
$ prisma db pull
Push the Prisma schema state to the database
$ prisma db push

You can get additional help on any of the prisma commands by adding the --help flag after the command.

Exit codes

All prisma CLI commands return the following codes when they exit:

  • exit code 0 when a command runs successfully
  • exit code 1 when a command errors
  • exit code 130 when the CLI receives a signal interrupt (SIGINT) message or if the user cancels a prompt. This exit code is available in Prisma versions 4.3.0 and later.

Commands

version (-v)

The version command outputs information about your current prisma version, platform, and engine binaries.

Options

The version command recognizes the following options to modify its behavior:

OptionRequiredDescription
--jsonNoOutputs version information in JSON format.

Examples

Output version information
$prisma version
Hide CLI results
Environment variables loaded from .env
prisma : 2.21.0-dev.4
@prisma/client : 2.21.0-dev.4
Current platform : windows
Query Engine : query-engine 2fb8f444d9cdf7c0beee7b041194b42d7a9ce1e6 (at C:\Users\veroh\AppData\Roaming\npm\node_modules\@prisma\cli\query-engine-windows.exe)
Migration Engine : migration-engine-cli 2fb8f444d9cdf7c0beee7b041194b42d7a9ce1e6 (at C:\Users\veroh\AppData\Roaming\npm\node_modules\@prisma\cli\migration-engine-windows.exe)
Format Binary : prisma-fmt 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 60ba6551f29b17d7d6ce479e5733c70d9c00860e
Studio : 0.365.0
Output version information (-v)
$prisma -v
Hide CLI results
Environment variables loaded from .env
prisma : 2.21.0-dev.4
@prisma/client : 2.21.0-dev.4
Current platform : windows
Query Engine : query-engine 2fb8f444d9cdf7c0beee7b041194b42d7a9ce1e6 (at C:\Users\veroh\AppData\Roaming\npm\node_modules\@prisma\cli\query-engine-windows.exe)
Migration Engine : migration-engine-cli 2fb8f444d9cdf7c0beee7b041194b42d7a9ce1e6 (at C:\Users\veroh\AppData\Roaming\npm\node_modules\@prisma\cli\migration-engine-windows.exe)
Format Binary : prisma-fmt 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 60ba6551f29b17d7d6ce479e5733c70d9c00860e
Studio : 0.365.0
Output version information as JSON
$prisma version --json
Hide CLI results
Environment variables loaded from .env
{
"prisma": "2.21.0-dev.4",
"@prisma/client": "2.21.0-dev.4",
"current-platform": "windows",
"query-engine": "query-engine 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules\\@prisma\\engines\\query-engine-windows.exe)",
"migration-engine": "migration-engine-cli 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules\\@prisma\\engines\\migration-engine-windows.exe)",
"format-binary": "prisma-fmt 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules\\@prisma\\engines\\prisma-fmt-windows.exe)",
"default-engines-hash": "60ba6551f29b17d7d6ce479e5733c70d9c00860e",
"studio": "0.365.0"
}

init

Bootstraps a fresh Prisma project within the current directory.

The init command does not interpret any existing files. Instead, it creates a prisma directory containing a bare-bones schema.prisma file within your current directory.

Arguments

ArgumentRequiredDescriptionDefault
--datasource-providerNoSpecifies the default value for the provider field in the datasource block. Options are sqlite, postgresql, mysql, sqlserver, mongodb and cockroachdb.postgresql
--urlNoDefine a custom datasource url.

Examples

Run prisma init
$prisma init
Hide CLI results
✔ Your Prisma schema was created at prisma/schema.prisma.
You can now open it in your favorite editor.
Next steps:
1. Set the DATABASE_URL in the .env file to point to your existing database. If your database has no tables yet, read https://pris.ly/d/getting-started
2. Set the provider of the datasource block in schema.prisma to match your database: postgresql, mysql, sqlite, sqlserver, mongodb or cockroachdb.
3. Run prisma db pull to turn your database schema into a Prisma schema.
4. Run prisma generate to generate Prisma Client. You can then start querying your database.
More information in our documentation:
https://pris.ly/d/getting-started
Run prisma init --datasource-provider sqlite
$prisma init --datasource-provider sqlite

The command output contains helpful information on how to use the generated files and begin using Prisma with your project.

Generated Assets

prisma/schema.prisma

An initial schema.prisma file to define your schema in:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}

.env

A file to define environment variables for your project:

# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#using-environment-variables
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL="file:./dev.db"
Run prisma init --url mysql://user:password@localhost:3306/mydb
$prisma init --url mysql://user:password@localhost:3306/mydb

The command output contains helpful information on how to use the generated files and begin using Prisma with your project.

Generated Assets

prisma/schema.prisma

A minimal schema.prisma file to define your schema in:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}

.env

A file to define environment variables for your project:

# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#using-environment-variables
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL="mysql://user:password@localhost:3306/mydb"

generate

The generate command generates assets like Prisma Client based on the generator and data model blocks defined in your prisma/schema.prisma file.

The generate command is most often used to generate Prisma Client with the prisma-client-js generator. This does three things:

  1. Searches the current directory and parent directories to find the applicable npm project. It will create a package.json file in the current directory if it cannot find one.
  2. Installs the @prisma/client into the npm project if it is not already present.
  3. Inspects the current directory to find a Prisma schema file to process. It will then generate a customized Prisma Client for your project.

Prerequisites

To use the generate command, you must add a generator definition in your schema.prisma file. The prisma-client-js generator, used to generate Prisma Client, can be added by including the following in your schema.prisma file:

generator client {
provider = "prisma-client-js"
}

Options

OptionRequiredDescriptionDefault
--data-proxyNoThe generate command will generate Prisma Client for use with the Data Proxy. Mutually exclusive with --accelerate and --no-engine.
--accelerateNoThe generate command will generate Prisma Client for use with Accelerate. Mutually exclusive with --data-proxy and --no-engine. Available in Prisma 5.1.0 and later.
--no-engineNoThe generate command will generate Prisma Client without an accompanied engine for use with Data Proxy or Accelerate. Mutually exclusive with --data-proxy and --accelerate. Available in Prisma 5.2.0 and later.
--watchNoThe generate command will continue to watch the schema.prisma file and re-generate Prisma Client on file changes.
Deprecation Warning
As of Prisma 5.2.0, --data-proxy and --accelerate are deprecated in favor of --no-engine as Prisma Client no longer requires an option to work with Accelerate or Data Proxy. All options are available and work similarly, but we recommend --no-engine as it prevents an engine from being downloaded which will greatly impact the size of apps deployed to serverless and edge functions.

Arguments

ArgumentRequiredDescriptionDefault
--schemaNoSpecifies the path to the desired schema.prisma file to be processed instead of the default path. Both absolute and relative paths are supported../schema.prisma, ./prisma/schema.prisma
--generatorNoSpecifies which generator to use to generate assets. This option may be provided multiple times to include multiple generators. By default, all generators in the target schema will be run.

Examples

Generate Prisma Client using the default schema.prisma path
$prisma generate
Hide CLI results
✔ Generated Prisma Client to ./node_modules/.prisma/client in 61ms
You can now start using Prisma Client in your code:
import { PrismaClient } from '@prisma/client'
// or const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
Explore the full API: https://pris.ly/d/client
Generate Prisma Client using a non-default schema.prisma path
$prisma generate --schema=./alternative/schema.prisma
Continue watching the schema.prisma file for changes to automatically re-generate Prisma Client
$prisma generate --watch
Hide CLI results
Watching... /home/prismauser/prisma/prisma-play/prisma/schema.prisma
✔ Generated Prisma Client to ./node_modules/.prisma/client in 45ms
Run the generate command with only a specific generator
$prisma generate --generator client
Run the generate command with multiple specific generators
$prisma generate --generator client --generator zod_schemas

Generated Assets

The prisma-client-js generator creates a customized client for working with your database within the ./node_modules/.prisma/client directory by default - you can customize the output folder.

introspect

Deprecation warning
From Prisma 3.0.0 onwards, the prisma introspect command is deprecated and replaced with the prisma db pull command.

validate

Validates the Prisma Schema Language of the Prisma schema file.

Arguments

ArgumentRequiredDescriptionDefault
--schemaNoSpecifies the path to the desired schema.prisma file to be processed instead of the default path. Both absolute and relative paths are supported../schema.prisma, ./prisma/schema.prisma

Examples

Validate a schema without errors
$prisma validate
Show CLI results
Validate a schema with validation errors
$prisma validate
Show CLI results

format

Formats the Prisma schema file, which includes validating, formatting, and persisting the schema.

Arguments

ArgumentRequiredDescriptionDefault
--schemaNoSpecifies the path to the desired schema.prisma file to be processed instead of the default path. Both absolute and relative paths are supported../schema.prisma, ./prisma/schema.prisma

Examples

Validate a schema without errors
$prisma format
Show CLI results
Formatting a schema with validation errors
$prisma format
Show CLI results

db

db pull

The db pull command connects to your database and adds Prisma models to your Prisma schema that reflect the current database schema.

Warning: The command will overwrite the current schema.prisma file with the new schema. Some manual changes or customization can be lost. Be sure to back up your current schema.prisma file (or commit your current state to version control to be able to revert any changes) before running db pull if it contains important modifications.

Introspection with the db pull command on the MongoDB connector samples the data instead of reading a schema.

Prerequisites

Before using the db pull command, you must define a valid datasource within your schema.prisma file.

For example, the following datasource defines a SQLite database file within the current directory:

datasource db {
provider = "sqlite"
url = "file:my-database.db"
}

Options

OptionRequiredDescriptionDefault
--forceNoForce overwrite of manual changes made to schema. The generated schema will be based on the introspected schema only.
--printNoPrints the created schema.prisma to the screen instead of writing it to the filesystem.

Arguments

ArgumentRequiredDescriptionDefault
--schemaNoSpecifies the path to the desired schema.prisma file to be processed instead of the default path. Both absolute and relative paths are supported../schema.prisma, ./prisma/schema.prisma

Examples

Analyze the database and write its schema to the schema.prisma file
$prisma db pull
Hide CLI results
Introspecting based on datasource defined in schema.prisma …
✔ Wrote Prisma data model into schema.prisma in 38ms
Run prisma generate to generate Prisma Client.
Specify an alternative schema.prisma file to read and write to
$prisma db pull --schema=./alternative/schema.prisma
Hide CLI results
Introspecting based on datasource defined in alternative/schema.prisma …
✔ Wrote Prisma data model into alternative/schema.prisma in 60ms
Run prisma generate to generate Prisma Client.
Display the generated schema.prisma file instead of writing it to the filesystem
$prisma db pull --print
Hide CLI results
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = "file:./hello-prisma.db"
}
model User {
email String @unique
name String?
user_id Int @id @default(autoincrement())
post Post[]
profile Profile[]
}
model Post {
content String?
post_id Int @id @default(autoincrement())
title String
author User? @relation(fields: [author_id], references: [user_id])
author_id Int?
}
model Profile {
bio String?
profile_id Int @id @default(autoincrement())
user User @relation(fields: [user_id], references: [user_id])
user_id Int @unique
}

db push

The db push command pushes the state of your Prisma schema file to the database without using migrations. It creates the database if the database does not exist.

This command is a good choice when you do not need to version schema changes, such as during prototyping and local development.

See also:

Prerequisites

Before using the db push command, you must define a valid datasource within your schema.prisma file.

For example, the following datasource defines a SQLite database file within the current directory:

datasource db {
provider = "sqlite"
url = "file:my-database.db"
}

Options

OptionsRequiredDescription
--skip-generateNoSkip generation of artifacts such as Prisma Client
--force-resetNoResets the database and then updates the schema - useful if you need to start from scratch due to unexecutable migrations.
--accept-data-lossNoIgnore data loss warnings. This option is required if as a result of making the schema changes, data may be lost.
--help / --hNoDisplays the help message

Arguments

ArgumentRequiredDescriptionDefault
--schemaNoSpecifies the path to the desired schema.prisma file to be processed instead of the default path. Both absolute and relative paths are supported../schema.prisma
./prisma/schema.prisma

Examples

Push the schema:

$prisma db push

Push the schema, accepting data loss:

$prisma db push --accept-data-loss

Push the schema with a custom schema location:

$prisma db push --schema=/tmp/schema.prisma

db seed

db seed changed from Preview to Generally Available (GA) in 3.0.1.

See Seeding your database

Options

OptionsRequiredDescription
--help / --hNoDisplays the help message
--NoAllows the use of custom arguments defined in a seed file

The -- argument/ delimiter/ double-dash is available from version 4.15.0 or later.

Examples

$prisma db seed

db execute

The db execute command is Generally Available in versions 3.13.0 and later. If you're using a version between 3.9.0 and 3.13.0, it is available behind a --preview-feature CLI flag.

This command is currently not supported on MongoDB.

This command applies a SQL script to the database without interacting with the Prisma migrations table. The script takes two inputs:

  • the SQL script, which can be provided either on standard input or in a file
  • the data source, which can either be the URL of the data source or the path to your Prisma schema file

The output of the command is connector-specific, and is not meant for returning data, but only to report success or failure.

See also:

Prerequisites

Before using the db execute command, if you do not use the --url option you must define a valid datasource within your schema.prisma file.

For example, the following datasource defines a SQLite database file within the current directory:

datasource db {
provider = "sqlite"
url = "file:my-database.db"
}

Options

One of the following data source inputs is required:

OptionsDescription
--urlURL of the data source to run the command on
--schemaPath to a Prisma schema file, uses the URL in the datasource block

One of the following script inputs is required:

OptionsDescription
--stdinUse the terminal standard input as the script to be executed
--filePath to a file. The content will be sent as the script to be executed

Other options:

OptionsRequiredDescription
--helpNoDisplays the help message.

Examples

  • Take the content of a SQL file located at ./script.sql and execute it on the database specified by the URL in the datasource block of your schema.prisma file:

    $prisma db execute --file ./script.sql --schema schema.prisma
  • Take the SQL script from standard input and execute it on the database specified by the data source URL given in the DATABASE_URL environment variable:

    $$ echo 'TRUNCATE TABLE dev;' | prisma db execute --stdin --url="$DATABASE_URL"

Prisma Migrate

Prisma Migrate changed from Preview to Generally Available (GA) in 2.19.0.

Does not apply for MongoDB
Instead of migrate dev and related commands, db push is used for MongoDB.

migrate dev

For use in development environments only, requires shadow database

The migrate dev command:

  1. Reruns the existing migration history in the shadow database in order to detect schema drift (edited or deleted migration file, or a manual changes to the database schema)
  2. Applies pending migrations to the shadow database (for example, new migrations created by colleagues)
  3. Generates a new migration from any changes you made to the Prisma schema before running migrate dev
  4. Applies all unapplied migrations to the development database and updates the _prisma_migrations table
  5. Triggers the generation of artifacts (for example, Prisma Client)

This command is not supported on MongoDB. Use db push instead.

See also:

Options

OptionRequiredDescriptionDefault
--create-onlyNoCreates a new migration based on the changes in the schema but does not apply that migration. Run migrate dev to apply migration.
--skip-seedNoSkip triggering seed
--skip-generateNoSkip triggering generators (for example, Prisma Client)
--help / --hNoDisplays the help message

If a schema drift is detected while running prisma migrate dev using --create-only, you will be prompted to reset your database.

Arguments

ArgumentRequiredDescriptionDefault
--nameNoThe name of the migration. If no name is provided, the CLI will prompt you.
--schemaNoSpecifies the path to the desired schema.prisma file to be processed instead of the default path. Both absolute and relative paths are supported../schema.prisma
./prisma/schema.prisma

Examples

Apply all migrations, then create and apply any new migrations:

$prisma migrate dev

Apply all migrations and create a new migration if there are schema changes, but do not apply it:

$prisma migrate dev --create-only

migrate reset

For use in development environments only

This command:

  1. Drops the database/schema if possible, or performs a soft reset if the environment does not allow deleting databases/schemas
  2. Creates a new database/schema with the same name if the database/schema was dropped
  3. Applies all migrations
  4. Runs seed scripts

This command is not supported on MongoDB. Use db push instead.

Options

OptionRequiredDescriptionDefault
--forceNoSkip the confirmation prompt
--skip-generateNoSkip triggering generators (for example, Prisma Client)
--skip-seedNoSkip triggering seed
--help / --hNoDisplays the help message

Arguments

ArgumentRequiredDescriptionDefault
--schemaNoSpecifies the path to the desired schema.prisma file to be processed instead of the default path. Both absolute and relative paths are supported../schema.prisma
./prisma/schema.prisma

Examples

$prisma migrate reset

migrate deploy

The migrate deploy command applies all pending migrations, and creates the database if it does not exist. Primarily used in non-development environments. This command:

  • Does not look for drift in the database or changes in the Prisma schema
  • Does not reset the database or generate artifacts
  • Does not rely on a shadow database

This command is not supported on MongoDB. Use db push instead.

Options

OptionRequiredDescriptionDefault
--help / --hNoDisplays the help message

Arguments

ArgumentRequiredDescriptionDefault
--schemaNoSpecifies the path to the desired schema.prisma file to be processed instead of the default path. Both absolute and relative paths are supported../schema.prisma
./prisma/schema.prisma

Examples

$prisma migrate deploy

migrate resolve

The migrate resolve command allows you to solve migration history issues in production by marking a failed migration as already applied (supports baselining) or rolled back.

Note that this command can only be used with a failed migration. If you try to use it with a successful migration you will receive an error.

This command is not supported on MongoDB. Use db push instead.

Options

OptionRequiredDescriptionDefault
--help / --hNoDisplays the help message

Arguments

ArgumentRequiredDescriptionDefault
--appliedNo*Record a specific migration as applied - for example --applied "20201231000000_add_users_table"
--rolled-backNo*Record a specific migration as rolled back - for example --rolled-back "20201231000000_add_users_table"./schema.prisma
./prisma/schema.prisma
--schemaNoSpecifies the path to the desired schema.prisma file to be processed instead of the default path. Both absolute and relative paths are supported../schema.prisma
./prisma/schema.prisma

You must specify either --rolled-back or --applied.

Examples

$prisma migrate resolve --applied 20201231000000_add_users_table
$prisma migrate resolve --rolled-back 20201231000000_add_users_table

migrate status

The prisma migrate status command looks up the migrations in ./prisma/migrations/* folder and the entries in the _prisma_migrations table and compiles information about the state of the migrations in your database.

This command is not supported on MongoDB. Use db push instead.

For example:

Status
3 migrations found in prisma/migrations
Your local migration history and the migrations table from your database are different:
The last common migration is: 20201127134938_new_migration
The migration have not yet been applied:
20201208100950_test_migration
The migrations from the database are not found locally in prisma/migrations:
20201208100950_new_migration

In versions 4.3.0 and later, prisma migrate status exits with exit code 1 in the following cases:

  • a database connection error occurs
  • there are migration files in the migrations directory that have not been applied to the database
  • the migration history in the migrations directory has diverged from the state of the database
  • no migration table is found
  • failed migrations are found

Options

OptionRequiredDescriptionDefault
--help / --hNoDisplays the help message

Arguments

ArgumentRequiredDescriptionDefault
--schemaNoSpecifies the path to the desired schema.prisma file to be processed instead of the default path. Both absolute and relative paths are supported../schema.prisma
./prisma/schema.prisma

Examples

$prisma migrate status

migrate diff

The migrate diff command is Generally Available in versions 3.13.0 and later. If you're using a version between 3.9.0 and 3.13.0, it is available behind a --preview-feature CLI flag.

This command is only partially supported for MongoDB. See the command options below for details.

This command compares two database schema sources and outputs a description of a migration taking the first to the state of the second.

The output can be given either as a human-readable summary (the default) or an executable script.

The migrate diff command can only compare database features that are supported by Prisma. If two databases differ only in unsupported features, such as views or triggers, then migrate diff will not show any difference between them.

The format of the command is:

$prisma migrate diff --from-... <source1> --to-... <source2>

where the --from-... and --to-... options are selected based on the type of database schema source. The supported types of sources are:

  • live databases
  • migration histories
  • Prisma data models
  • an empty schema

Both schema sources must use the same database provider. For example, a diff comparing a PostgreSQL data source with a SQLite data source is not supported.

See also:

Prerequisites

Before using the migrate diff command, if you are using the --from-schema-datasource or --to-schema-datasource you must define a valid datasource within your schema.prisma file.

For example, the following datasource defines a SQLite database file within the current directory:

datasource db {
provider = "sqlite"
url = "file:my-database.db"
}

Options

One of the following --from-... options is required:

OptionsDescriptionNotes
--from-urlA data source URL
--from-migrationsPath to the Prisma Migrate migrations directoryNot supported in MongoDB
--from-schema-datamodelPath to a Prisma schema file, uses the data model for the diff
--from-schema-datasourcePath to a Prisma schema file, uses the URL in the datasource block for the diff
--from-emptyAssume that you the data model you are migrating from is empty

One of the following --to-... options is required:

OptionsDescriptionNotes
--to-urlA data source URL
--to-migrationsPath to the Prisma Migrate migrations directoryNot supported in MongoDB
--to-schema-datamodelPath to a Prisma schema file, uses the data model for the diff
--to-schema-datasourcePath to a Prisma schema file, uses the URL in the datasource block for the diff
--to-emptyAssume that you the data model you are migrating to is empty

Other options:

OptionsRequiredDescriptionNotes
--shadow-database-urlNoURL for the shadow databaseOnly required if using --to-migrations or --from-migrations
--scriptNoOutputs a SQL script instead of the default human-readable summaryNot supported in MongoDB
--exit-codeNoChange the exit code behavior to signal if the diff is empty or not (Empty: 0, Error: 1, Not empty: 2). Default behavior is Success: 0, Error: 1.
--helpNoDisplays the help message.

Examples

  • Compare two databases specified by their data source URL, and output the default human-readable summary:

    $prisma migrate diff \
    $ --from-url "$DATABASE_URL" \
    $ --to-url "postgresql://login:password@localhost:5432/db2"
  • Compare the state of a database with a URL of $DATABASE_URL to the schema defined by the migrations in the ./prisma/migrations directory, and output the differences to a script script.sql:

    $prisma migrate diff \
    $ --from-url "$DATABASE_URL" \
    $ --to-migrations ./prisma/migrations \
    $ --shadow-database-url $SHADOW_DATABASE_URL \
    $ --script > script.sql

Studio

studio

The studio command allows you to interact with and manage your data interactively. It does this by starting a local web server with a web app configured with your project's data schema and records.

Prerequisites

Before using the studio command, you must define a valid datasource within your schema.prisma file.

For example, the following datasource defines a SQLite database file within the current directory:

datasource db {
provider = "sqlite"
url = "file:my-database.db"
}

Options

The studio command recognizes the following options:

OptionRequiredDescriptionDefault
-b, --browserNoThe browser to auto-open Studio in.<your-default-browser>
-h, --helpNoShow all available options and exit
-p, --portNoThe port number to start Studio on.5555

Arguments

ArgumentRequiredDescriptionDefault
--schemaNoSpecifies the path to the desired schema.prisma file to be processed instead of the default path. Both absolute and relative paths are supported../schema.prisma
./prisma/schema.prisma

Examples

Start Studio on the default port and open a new browser tab to it

$prisma studio

Start Studio on a different port and open a new browser tab to it

$prisma studio --port 7777

Start Studio and open a Firefox tab to it

$prisma studio --browser firefox

Start Studio without opening a new browser tab to it

$prisma studio --browser none

package.json entry options

schema

The path to the desired schema.prisma file can be specified with the prisma.schema entry in the package.json file. The path defines the file the Prisma CLI should use when you run any of the CLI commands. Both absolute and relative paths are supported.

"package.json"
1{
2 "name": "my-project",
3 "version": "1.0.0",
4 "prisma": {
5 "schema": "./custom-path-to-schema/schema.prisma"
6 }
7}

This is available from version 2.7.0 and later.

seed

The command used to populate the datasource is specified in the prisma.seed entry in the package.json file. It is used when prisma db seed is invoked or triggered.

See Seeding your database

"package.json"
1{
2 "name": "my-project",
3 "version": "1.0.0",
4 "prisma": {
5 "seed": "node ./prisma/seed.js"
6 }
7}

This is available from version 3.0.1 and later.

Using a HTTP proxy for the CLI

Prisma CLI supports custom HTTP proxies. This is particularly relevant when being behind a corporate firewall.

To activate usage of the proxy, provide either of the following environment variables:

  • HTTP_PROXY or http_proxy: Proxy URL for http traffic, for example http://localhost:8080
  • HTTPS_PROXY or https_proxy: Proxy URL for https traffic, for example https://localhost:8080
Edit this page on GitHub