Prisma ORM cheatsheet

Prisma ORM: CLI and migrations

10 common Prisma ORM tasks.

Install Prisma

Add the CLI as a development dependency and the client as a dependency.

npm install prisma --save-dev
npm install @prisma/client

Initialize Prisma

Create a prisma folder with schema.prisma and a .env file for DATABASE_URL.

npx prisma init --datasource-provider postgresql

Create and apply a migration

Turn schema changes into a SQL migration and apply it to the development database.

npx prisma migrate dev --name init

Apply migrations in production

Apply pending migrations without creating new ones. Use it in CI and deployments.

npx prisma migrate deploy

Generate the client

Regenerate the client after changing the schema.

npx prisma generate

Browse data in a UI

Open Prisma Studio in the browser to view and edit rows.

npx prisma studio

Sync the schema without migrations

Push the schema straight to the database. Good for prototyping, not for production history.

npx prisma db push

Introspect an existing database

Create or update the schema from a database that already exists.

npx prisma db pull

Reset the development database

Drop the database, recreate it and re-apply all migrations.

npx prisma migrate reset

Caution: Deletes all data in the database. Never run it against production.

Validate and format the schema

Check the schema for errors and format it.

npx prisma validate
npx prisma format

Was this page helpful?