Skip to main content

Command Palette

Search for a command to run...

Prisma ORM Explained: The Commands Every Developer Should Actually Know

Learn Prisma ORM the practical way. Understand migrate dev, generate, migrate deploy, Prisma Studio, and production workflows with real examples.

Updated
β€’5 min read
Prisma ORM Explained: The Commands Every Developer Should Actually Know
A
πŸ€– Curious AI enthusiast and Software Engineer with 7+ years of experience. πŸ› οΈ I enjoy getting my hands dirty with new technologies β€” experimenting, building side projects, and learning by doing. πŸš€ Currently exploring how AI can enhance real-world web applications.

The first time I used Prisma, I thought it was just another ORM.

A few weeks later, I realized Prisma is actually three things:

  • A database migration tool

  • A type-safe query builder

  • A schema management system

The confusion usually starts when developers see commands like:

prisma migrate dev
prisma generate
prisma migrate deploy

They sound similar, but they do very different things.

This guide is the Prisma cheat sheet I wish I had when starting out.


What is Prisma?

Prisma ORM helps you interact with your database using a type-safe API instead of writing raw SQL everywhere. It also manages schema changes through migrations and generates TypeScript types directly from your schema. (Prisma)

Think of it like:

Database Schema β†’ Prisma β†’ Type-Safe API β†’ Your Application

Instead of:

SELECT * FROM users;

You write:

const users = await prisma.user.findMany();

πŸ“ Git-Friendly Migrations

Every schema change becomes a migration file that can be committed to Git.

prisma/
└── migrations/

This means your database history lives alongside your code. (Prisma)


πŸš€ Type Safety

When you update your schema:

model User {
  id    Int    @id
  email String
}

Prisma automatically updates your TypeScript types.

No more:

user.emial

bugs.


πŸ”„ Easier Refactoring

Changing database columns, relationships, or tables becomes much safer because Prisma updates the generated client accordingly.


Getting Started with Prisma

Step 1: Install Prisma

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

Or globally:

npm install -g prisma

Step 2: Initialize Prisma

npx prisma init --output ../generated/prisma

This creates:

prisma/
β”œβ”€β”€ schema.prisma
└── migrations/

Existing Database?

Configure your database URL and pull your schema:

prisma db pull

Prisma will inspect your database and generate models automatically. (Prisma)


Create Your First Model

Inside:

Schema.prisma

model Restaurant {
  id   Int    @id @default(autoincrement())
  name String
}

Create Database Tables

Run:

npx prisma migrate dev --name init

Prisma will:

βœ… Compare schemas

βœ… Generate migration SQL files

βœ… Apply migrations to your development database configured in .env

βœ… Update migration history

βœ… Create database tables

Prisma stores migration history in the _prisma_migrations table. (Prisma)


The Prisma Commands You Need to Know

1. Prisma Studio

Launch Prisma's built-in database GUI:

npx prisma studio

Opens:

http://localhost:5555

Think of it as a lightweight admin panel for your database.

You can:

  • View records

  • Edit data

  • Delete records

  • Inspect relationships

without writing SQL.


2. prisma migrate dev

Probably the most important command:

npx prisma migrate dev --name add_users

What actually happens?

  1. Checks migration history

  2. Detects schema changes

  3. Creates a migration file

  4. Applies migration to your development database

  5. Updates _prisma_migrations history table

Prisma explicitly recommends using this command only during development. (Prisma)

⚠️ Never run this on production.


3. prisma generate

npx prisma generate

This regenerates the Prisma Client based on your schema.

Why does this matter?

Because your code uses generated APIs like:

prisma.user.findMany()

Whenever your schema changes, regenerate the client.

npx prisma generate

Prisma Client is generated from your schema and provides the type-safe API your application uses. (Prisma)


4. prisma migrate deploy

This is the production command.

npx prisma migrate deploy

Unlike migrate dev, it does not:

❌ Generate migrations

❌ Detect schema drift

❌ Create migration files

It simply:

βœ… Looks for migration files already committed to Git

βœ… Applies any pending migrations

That's exactly why it's safe for production environments. (Prisma)

A typical workflow:

Development
      ↓
prisma migrate dev
      ↓
Git Commit
      ↓
Production
      ↓
prisma migrate deploy

5. prisma migrate status

Check whether your database and migration files are in sync:

npx prisma migrate status

Useful before deployments.


6. prisma migrate reset

Need a clean slate?

npx prisma migrate reset

This command:

  • Drops the database

  • Recreates it

  • Reapplies all migrations

⚠️ All data is lost.

Use only in development environments. (Prisma)


Too Many Migration Files?

Every time you run:

npx prisma migrate dev --name something

a new migration gets created.

During MVP development, it's common to accumulate dozens of migrations & that's totally normal because that is how you see your schema history.

Example:

migrations/
β”œβ”€β”€ add_user
β”œβ”€β”€ add_role
β”œβ”€β”€ add_status
β”œβ”€β”€ fix_role
β”œβ”€β”€ fix_role_again

Many teams periodically clean this up.

Reset:

npx prisma migrate reset

Delete:

prisma/migrations/

Create a fresh migration:

npx prisma migrate dev --name init

Result:

migrations/
└── init

Much cleaner.


Development

# Modify schema.prisma

npx prisma migrate dev --name add_feature

npx prisma generate

npx prisma studio

Production

# CI/CD

npx prisma migrate deploy

Never:

npx prisma migrate dev

on production servers. Prisma's documentation recommends using migrate deploy for production and CI/CD workflows. (Prisma)


Final Thoughts

Could you build your app using only PostgreSQL and raw SQL files?

Absolutely.

But once your project starts growing, Prisma gives you:

  • Type safety

  • Migration history

  • Better developer experience

  • Cleaner code

  • Easier schema management

For small prototypes, raw SQL is fine.

For real-world TypeScript applications, Prisma quickly pays for itself.


Useful Resources