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.

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();
Why Prisma Is So Popular
π 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?
Checks migration history
Detects schema changes
Creates a migration file
Applies migration to your development database
Updates
_prisma_migrationshistory 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.
My Recommended Prisma Workflow
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.





