Hello @lumenwrites

npx prisma db push is meant for development use only. The development db is considered "resettable" and "seedable" as its used to develop your migrations and to test/tweak them if needed. Looks like you have used it in your production environment. In production, you should use npx prisma migrate deploy and it would ensure your db won't get reset in any case.

Now in order to resolve your current situation we need to tweak the migrations history using some primitives which migrate provides like the diff command(https://www.prisma.io/docs/reference/api-reference/command-reference#migrate-diff)

  1. You will need to generate a new migration which will be the difference between migrations history stored in your disk in the migrations folder and your production database. The --to-schema-datasource flag here point to the database stored in your .env file but you can also change this flag to --to-url if you prefer to give the database url in the command itself.
mkdir -p prisma/migrations/add-comments-and-post/
npx prisma migrate diff --from-migrations prisma/migrations --to-schema-datasource prisma/schema.prisma --shadow-database-url   --script >  prisma/migrations/add-comments-and-post/migration.sql

The --shadow-database-url parameter is required and you will need to point it to any empty postgres database either a local one or hosted one. Prisma will use that to reply migration history and calculate the diff.

This will create a new migration in prisma/migrations/add-comments-and-post/migration.sql which will have the SQL for the model you have added via db push.

  1. Now you have the migration ready, we will need to mark it as applied. This is because those tables already exists in the database and we can't run the actual CREATE sql statements to the database. We will just mark the migration as applied as it was already applied when you ran npx prisma db push.
npx prisma migrate resolve --applied add-comments-and-post
  1. Now, you should be ready to go. Run npx prisma migrate dev once now and it should say everything is in sync.
🌐
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.
Discussions

Difference between prisma db push and prisma migrate dev - Stack Overflow
what is the difference between prisma db push and prisma migrate dev ? When should I use one over the other. Docs say that prisma db push is about schema prototyping only and I don't understand wha... More on stackoverflow.com
🌐 stackoverflow.com
Where do you actually run prisma migrate deploy?
If you want an easy way to develop, I can recommend Planetscale which has a very generous free tier. It's a mysql db service that has branches like your code. That means you can develop code locally, run prisma db push and then merge the dev branch of your db into prod when you want. More on reddit.com
🌐 r/node
18
4
December 11, 2022
`npx prisma migrate dev --name init` fails in starter project
Bug description I was following this instruction in the setup page: "Set up your database (schema migration) Initialize your new database by running a schema migration to create the necessary tables from the sample project. npx prisma mi... More on github.com
🌐 github.com
1
January 9, 2025
`npx prisma migrate dev` hangs up
Bug description When running the command npx prisma migrate dev, it hands up after returning the following message: Environment variables loaded from .env Prisma schema loaded from prisma/schema.pr... More on github.com
🌐 github.com
19
January 16, 2023
Top answer
1 of 1
6

Hello @lumenwrites

npx prisma db push is meant for development use only. The development db is considered "resettable" and "seedable" as its used to develop your migrations and to test/tweak them if needed. Looks like you have used it in your production environment. In production, you should use npx prisma migrate deploy and it would ensure your db won't get reset in any case.

Now in order to resolve your current situation we need to tweak the migrations history using some primitives which migrate provides like the diff command(https://www.prisma.io/docs/reference/api-reference/command-reference#migrate-diff)

  1. You will need to generate a new migration which will be the difference between migrations history stored in your disk in the migrations folder and your production database. The --to-schema-datasource flag here point to the database stored in your .env file but you can also change this flag to --to-url if you prefer to give the database url in the command itself.
mkdir -p prisma/migrations/add-comments-and-post/
npx prisma migrate diff --from-migrations prisma/migrations --to-schema-datasource prisma/schema.prisma --shadow-database-url   --script >  prisma/migrations/add-comments-and-post/migration.sql

The --shadow-database-url parameter is required and you will need to point it to any empty postgres database either a local one or hosted one. Prisma will use that to reply migration history and calculate the diff.

This will create a new migration in prisma/migrations/add-comments-and-post/migration.sql which will have the SQL for the model you have added via db push.

  1. Now you have the migration ready, we will need to mark it as applied. This is because those tables already exists in the database and we can't run the actual CREATE sql statements to the database. We will just mark the migration as applied as it was already applied when you ran npx prisma db push.
npx prisma migrate resolve --applied add-comments-and-post
  1. Now, you should be ready to go. Run npx prisma migrate dev once now and it should say everything is in sync.
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.

🌐
Reddit
reddit.com › r/node › where do you actually run prisma migrate deploy?
r/node on Reddit: Where do you actually run prisma migrate deploy?
December 11, 2022 -

I'm working on a little project with supabase and prisma, I've just been using one dev database which I update with prisma migrate dev. For production migrations, you're supposed to use prisma migrate deploy, which the prisma docs say to put in a CI/CD pipeline.

  • I don't have a CI/CD pipeline

  • I can't run it locally from my project directory, cause prisma uses the DATABASE_URL environment, which is pointing to my dev database

So I'm wondering where y'all would actually run prisma migrate deploy from? Should I just bite the bullet and learn some github actions? Or is there an easier way?

EDIT: The prisma docs recommend using dotenv-cli to use switch between .env files, but I'm kinda worried that I might fuck up somehow and end up running prisma migrate reset on my prod database, and delete everything. But, seems like that might be my plan until I figure out some CI/CD stuff.

Still definitely open to any advice though!

🌐
GitHub
github.com › prisma › prisma › issues › 26014
`npx prisma migrate dev --name init` fails in starter project · Issue #26014 · prisma/prisma
January 9, 2025 - in the command line, run npx prisma migrate dev --name init · This bug report was generated after receiving an error. The database should be overwritten. I did this because I was trying to add new models and stream changes on the table.
Author   prisma
Find elsewhere
🌐
Kitemetric
kitemetric.com › blogs › mastering-prisma-migrations-dev-vs-deploy
Mastering Prisma Migrations: Dev vs. Deploy | Kite Metric
Master Prisma's database migration commands: `migrate dev` for local development and `migrate deploy` for production. Learn the key differences and best practices for safe and efficient schema management.
🌐
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.
🌐
GitHub
github.com › prisma › prisma › discussions › 19185
`prisma migrate dev` prompts me to reset my database, but I just baselined. · prisma/prisma · Discussion #19185
I entered my remote development database credentials in environment variables and ran npx prisma db pull. I confirmed that my schema prisma file is updated with the schema from my db. I ran npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > prisma/migrations/0_init/migration.sql to create an initial migration.
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 17338
`npx prisma migrate dev` hangs up · Issue #17338 · prisma/prisma
January 16, 2023 - Bug description When running the command npx prisma migrate dev, it hands up after returning the following message: Environment variables loaded from .env Prisma schema loaded from prisma/schema.prisma Datasource "db": PostgreSQL databas...
Author   prisma
🌐
Prisma
prisma.io › home › postgresql › postgresql › postgresql
Quickstart: Prisma ORM with PostgreSQL (10 min) | Prisma Documentation
import "dotenv/config"; import { defineConfig, env } from "prisma/config"; export default defineConfig({ schema: "prisma/schema.prisma", migrations: { path: "prisma/migrations", }, datasource: { url: env("DATABASE_URL"), }, });
🌐
Prisma
prisma.io › home › local development › local development › local development
Local development with Prisma Postgres | Prisma Documentation
Make sure the local Prisma Postgres server is running before running the prisma migrate dev command. If you must use a different port, append --port <number> (for example, npx prisma migrate dev --port 5422) and update your DATABASE_URL (or other connection settings) to match.
🌐
PlanetScale
planetscale.com › guides › frameworks and orms › prisma › automatic prisma migrations
Automatic Prisma migrations - PlanetScale
1 week ago - You can still see the history of your schema changes in PlanetScale. Add Prisma to your project using npm install prisma --save-dev or yarn add prisma --dev (depending on what package manager you prefer). Run npx prisma init ...
🌐
DEV Community
dev.to › digitaldrreamer › prisma-migration-stuck-7l5
Prisma migration stuck? - DEV Community
January 7, 2026 - I was trying to npx prisma migrate dev --name init to a supabase Postgre db. It was stuck here for...
🌐
MCP Servers
mcpservers.org › home › agent skills library › prisma-cli-migrate-deploy
prisma-cli-migrate-deploy | Agent Skills Library
Any non-development environment · prisma migrate deploy · # GitHub Actions example - name: Apply migrations run: npx prisma migrate deploy env: DATABASE_URL: ${{ secrets.DATABASE_URL }} # Run migrations before starting app CMD npx prisma migrate deploy && node dist/index.js ·
🌐
Medium
medium.com › @panat.siriwong › how-to-sync-prisma-migrations-between-prod-and-test-databases-after-divergence-528bd372d6f4
How to Sync Prisma Migrations Between Prod and Test Databases After Divergence | by Panat Por | Medium
August 18, 2024 - Rename your current prisma/migrations folder to prisma/migrations_backup. ... Run a command to generate the current Prod schema. ... You will now have a new schema.prisma file that reflects the Prod schema.
🌐
Prisma
prisma.io › home › generating down migrations › generating down migrations › generating down migrations › generating down migrations
Generating down migrations | Prisma Documentation
This requires the use of the migrate ... to revert your schema.prisma file to its state before the up migration, and generate a new migration with the migrate dev command....
🌐
Qiita
qiita.com › typescript
Prismaのマイグレーション管理に入門する #TypeScript - Qiita
April 17, 2025 - $ npx prisma migrate dev --name third Environment variables loaded from prisma/.env Prisma schema loaded from prisma/schema Datasource "db": SQL Server database Applying migration `20241218121233_second` The following migration(s) have been applied: migrations/ └─ 20241202114138_first/ └─ migration.sql └─ 20241218121233_second/ └─ migration.sql ✔ Enter a name for the new migration: …
🌐
Prisma
prisma.io › home › mysql › mysql › mysql
Using Prisma Migrate with TypeScript and MySQL
Prerequisites1. Create a new project2. Install required dependencies3. Configure ESM support4. Initialize Prisma ORM5. Define your data model6. Create and apply your first migration7. Instantiate Prisma Client8. Write your first query9.