They serve two different environments. The prisma db push is not to be used in your production environment, as stated in the docs

db push uses the same engine as Prisma Migrate to synchronize your Prisma schema with your database schema, and is best suited for schema prototyping. The db push command:

  1. Introspects the database to infer and executes the changes required to make your database schema reflect the state of your Prisma schema.

  2. By default, after changes have been applied to the database schema, generators are triggered (for example, Prisma Client). You do not need to manually invoke prisma generate.

  3. If db push anticipates that the changes could result in data loss, it will:

  • Throw an error
  • Require the --accept-data-loss option if you still want to make the changes

Note: db push does not interact with or rely on migrations. The migrations table will not be updated, and no migration files will be generated.

The prisma migrate dev is used in you local environment, as explained in the docs

migrate dev is a development command and should never be used in a production environment.

This command:

  1. Replays 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, the Prisma Client)

The migrate dev command will prompt you to reset the database in the following scenarios:

  • Migration history conflicts caused by modified or missing migrations
  • The database schema has drifted away from the end-state of the migration history

If you have any other question regarding this, there is this comparison in the docs explaining when to use one or the other.

Answer from Daniel Olavio Ferreira on Stack Overflow
🌐
Softpost
softpost.org › prisma › difference-between-prisma-migrate-and-prisma-generate
difference between prisma migrate and prisma generate
Prisma migrate is used for managing database migrations in your development environment and prisma generate is used to create prisma client
🌐
Prisma
prisma.io › home › overview of prisma migrate › overview of prisma migrate
Prisma Migrate: Database, Schema, SQL Migration Tool | Prisma Documentation
Declarative: The data model is described in a declarative way in the Prisma schema. Prisma Migrate generates SQL migration files from that data model.
Discussions

Difference between prisma db push and prisma migrate dev - Stack Overflow
You do not need to manually invoke prisma generate. If db push anticipates that the changes could result in data loss, it will: ... Note: db push does not interact with or rely on migrations. More on stackoverflow.com
🌐 stackoverflow.com
Correct pattern of Generating Migrations
I am using prisma with postgres. I have a fresh DB, starting from scratch. I add a new schema to the schema.prisma file. I run prisma generate. It succeeds, tells me I can start using the client in... More on github.com
🌐 github.com
2
1
How do I use Prisma without having to wipe my database all the time?
Think of it like this: You have a table with some users, none of which have a last name. Now you update schema.prisma with a required column called lastName, without a default value. How should Prisma handle the migration for you? Since Prisma can't guess the last name of every user, the only reasonable thing it can do is to ask you to recreate the data—which means resetting that table. To work around that, you need two migrations. You first set the column's default value to a placeholder—ensuring every row has a value. You then make a second migration where you remove the default value. This is, of course, just one of many reasons for why Prisma would want to reset a table, or sometimes even the whole database (if the effect is large enough). Prisma migrations are great, and they make life so much easier! But you still need to consider how they are applied and design your database accordingly: Prisma won't be able to magically solve the logical impossibilities that may occur otherwise. So, just like with everything else in programming, you need to be careful and considerate, and the more you practice; the easier it gets. I think Prisma sometimes overpromises on "making database design easy". It sure makes it easier, but you still need to think about what's going on behind the scenes. The way it abstracts the database design behind a neat little schema—together with its automatic migrations—can sometimes make you miss the forest for all the trees. More on reddit.com
🌐 r/node
39
34
December 5, 2023
For those who use Prisma, do you use prisma migration deploy in production?
Hi 👋🏽 Alex here from the Prisma team. Ideally, it would be best to run prisma migrate deploy as part of your CI/CD pipeline when deploying your application to production. The prisma migrate deploy command will: Compare the applied changes with your current migrations history Apply any pending migrations to sync your Prisma schema with your database schema. Here's a fairly simple example of how this would look like with a GitHub Action: name: test on: push branches: - main jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v3 with: node-version: '16' - run: npm install - run: npm run build - run: npx prisma migrate deploy This assumes you've set the DATABASE_URL environment variable in the Action. We also have docs on Deploying database changes with Prisma Migrate you can also refer to. We also have a workshop on Deep dive into database workflows with Prisma Migrate which you might also find resourceful. 🙂 More on reddit.com
🌐 r/node
11
33
July 14, 2022
🌐
GitHub
github.com › prisma › prisma › discussions › 24571
How should migration be done to Production? · prisma/prisma · Discussion #24571
However, this should be followed by creating a migration to capture these changes. ... Make Changes to schema.prisma: Update your schema.prisma file with the desired changes. Generate and Apply Migrations: Use the prisma migrate dev command to generate and apply migrations during development with npx prisma migrate dev.
Author   prisma
🌐
Prisma
prisma.io › home › getting started with prisma migrate › getting started with prisma migrate › getting started with prisma migrate
Getting started with Prisma Migrate | Prisma Documentation
Create an initial migration using the prisma migrate command: ... This will generate a migration with the appropriate commands for your database.
🌐
Prisma
prisma.io › migrate
Prisma Migrate | Database Migrations for Prisma ORM
Prisma Migrate generates migrations based on changes in the Prisma schema – a human-readable declarative definition of your database schema.
Top answer
1 of 4
19

They serve two different environments. The prisma db push is not to be used in your production environment, as stated in the docs

db push uses the same engine as Prisma Migrate to synchronize your Prisma schema with your database schema, and is best suited for schema prototyping. The db push command:

  1. Introspects the database to infer and executes the changes required to make your database schema reflect the state of your Prisma schema.

  2. By default, after changes have been applied to the database schema, generators are triggered (for example, Prisma Client). You do not need to manually invoke prisma generate.

  3. If db push anticipates that the changes could result in data loss, it will:

  • Throw an error
  • Require the --accept-data-loss option if you still want to make the changes

Note: db push does not interact with or rely on migrations. The migrations table will not be updated, and no migration files will be generated.

The prisma migrate dev is used in you local environment, as explained in the docs

migrate dev is a development command and should never be used in a production environment.

This command:

  1. Replays 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, the Prisma Client)

The migrate dev command will prompt you to reset the database in the following scenarios:

  • Migration history conflicts caused by modified or missing migrations
  • The database schema has drifted away from the end-state of the migration history

If you have any other question regarding this, there is this comparison in the docs explaining when to use one or the other.

2 of 4
11
  • Prisma db push syncs (and formats) your prisma schema to that of your database schema.
  • While prisma migrate dev "command automatically generates SQL migration files (saved in /prisma/migrations) and applies them to the database".

The main difference between both is the generation of the migration files.

🌐
Prisma
prisma.io › home › development and production › development and production › development and production › development and production
Development and production | Prisma Documentation
Does not detect drift (production database schema differs from migration history end state - for example, due to a hotfix) Does not reset the database or generate artifacts (such as Prisma Client)
Find elsewhere
🌐
Kitemetric
kitemetric.com › blogs › mastering-prisma-migrations-dev-vs-deploy
Mastering Prisma Migrations: Dev vs. Deploy | Kite Metric
Schema Drift Detection: Compares your schema.prisma with the database. Discrepancies are identified, highlighting potential issues. Migration File Generation: Creates a SQL migration file (e.g., in prisma/migrations).
🌐
Prisma
prisma.io › home › dev › dev › dev
prisma migrate dev | Create & Apply Migrations | Prisma Documentation
Create and apply migrations during development with prisma migrate dev. Uses shadow database. Generates migration from schema changes.
🌐
Medium
medium.com › @bryantbrock › data-migrations-with-prisma-94909cb0c0c0
Data migrations with Prisma. For production applications (and… | by Bryant Brock | Medium
December 19, 2023 - Be sure to cover all your basis; grep your codebase many times to make sure you are correctly reading from the right columns. You should see error messages if you are still reading from the old columns after you have re-generated your Prisma Client (w/ the added @ignore attributes) since they won’t be recognized.
🌐
Reddit
reddit.com › r/node › how do i use prisma without having to wipe my database all the time?
r/node on Reddit: How do I use Prisma without having to wipe my database all the time?
December 5, 2023 -

I'm using Prisma for a large project I've been working on for the past few months, and I still don't understand the flow of it. At first I was migrating every time I made a change to my schema, and constantly getting the "All data will be lost" prompt. Since then I've learned to use `db push` while developing and then migrate when a feature is finished, but it's still constantly making me reset my database.

Right now I'm using the same db for dev and staging (because I don't want to pay for 2 different ones) but I'd imagine this would still be an issue if I had separate databases. What do I need to do to stop being forced to reset my db? Or, at least, how would I migrate my development db to mirror my production db without it being wiped?

As you can probably tell, this is my first time working with Prisma (or any ORM, in depth) so this might be a stupid question, but I can't find much online besides general tutorials. Any help would be greatly appreciated!

Top answer
1 of 5
23
Think of it like this: You have a table with some users, none of which have a last name. Now you update schema.prisma with a required column called lastName, without a default value. How should Prisma handle the migration for you? Since Prisma can't guess the last name of every user, the only reasonable thing it can do is to ask you to recreate the data—which means resetting that table. To work around that, you need two migrations. You first set the column's default value to a placeholder—ensuring every row has a value. You then make a second migration where you remove the default value. This is, of course, just one of many reasons for why Prisma would want to reset a table, or sometimes even the whole database (if the effect is large enough). Prisma migrations are great, and they make life so much easier! But you still need to consider how they are applied and design your database accordingly: Prisma won't be able to magically solve the logical impossibilities that may occur otherwise. So, just like with everything else in programming, you need to be careful and considerate, and the more you practice; the easier it gets. I think Prisma sometimes overpromises on "making database design easy". It sure makes it easier, but you still need to think about what's going on behind the scenes. The way it abstracts the database design behind a neat little schema—together with its automatic migrations—can sometimes make you miss the forest for all the trees.
2 of 5
19
bruh
🌐
LogRocket
blog.logrocket.com › home › effortless database schema migration with prisma
Effortless database schema migration with Prisma - LogRocket Blog
June 4, 2024 - You can use prisma migrate dev --create-only to create the migration file, and manually modify it to address the underlying issue(s). Then run prisma migrate dev to apply it and verify it works. This is primarily because we have one or more rows in the users table and the migration generated by Prisma is potentially destructive.
🌐
Prisma
prisma.io › home › understanding migrations › understanding migrations › understanding migrations › understanding migrations
A mental model for Prisma Migrate | Prisma Documentation
The prisma migrate dev command allows you to track the changes you make to your database. The prisma migrate dev command automatically generates SQL migration files (saved in /prisma/migrations) and applies them to the database.
🌐
Reddit
reddit.com › r/node › for those who use prisma, do you use prisma migration deploy in production?
r/node on Reddit: For those who use Prisma, do you use prisma migration deploy in production?
July 14, 2022 -

I'm doing a personal project, deploying my back end into aws Fargate and database postgres in RDS. Never used migrations before (others project we runned the sql command into database, I don't if this is a bad practice haha, but it is how it was), and I got to the point where, where/how I am supposed to run the migration deploy in the pipeline? I thought in, for now, just run the migrations generated into the database, as I am used.

So, there's a default procedure?

🌐
PlanetScale
planetscale.com › guides › frameworks and orms › prisma › automatic prisma migrations
Automatic Prisma migrations - PlanetScale
2 weeks ago - We recommend prisma db push over prisma migrate dev for the following reasons: PlanetScale provides Online Schema Changes that are deployed automatically when you merge a deploy request and prevents blocking schema changes that can lead to downtime. This is different from the typical Prisma workflow which uses prisma migrate in order to generate SQL migrations for you based on changes in your Prisma schema.
🌐
DEV Community
dev.to › this-is-learning › its-prisma-time-migrations-7pk
It's Prisma Time - Migrations - DEV Community
February 2, 2022 - npx prisma migrate dev --name rename_author_columns --create-only · This command generates the new migration file but now we have to edit it to avoid data loss.
🌐
Prisma
prisma.io › home › customizing migrations › customizing migrations › customizing migrations › customizing migrations
Customizing migrations | Prisma Documentation
To actually rename a field and avoid data loss when you run the migration in production, you need to modify the generated migration SQL before applying it to the database.
🌐
Prisma
prisma.io › home › migrate › migrate
prisma migrate | Database Migration Commands | Prisma Documentation
Create and apply database migrations with Prisma. migrate dev for development, migrate deploy for production, status, resolve, diff, and reset.
🌐
Fig
fig.io › manual › prisma › migrate › dev
prisma migrate dev | Fig
The migrate dev command updates your database using migrations files during development