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 › push › push › push
prisma db push | Apply Schema to Database (No Migrations) | Prisma Documentation
Push Prisma schema changes directly to the database with prisma db push. Ideal for prototyping and local dev. No migration history required.
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.
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
`npx prisma db push` and `npx prisma migrate` error when there is a table that starts with `_`
Bug description I try to keep a unified style in my database, so I specify a unique name for each table. But when using the implicit many-to-many relation, I get tables that start with _, so I have to name my utility tables with _ at the... More on github.com
🌐 github.com
4
March 22, 2023
database - Why does the command npx prisma db push not progress and fail to push my models to Supabase? - Stack Overflow
When I run npx prisma db push, the command does not proceed beyond this part. I've been waiting for almost 30 minutes, and it doesn't progress further. C:\Users\matti\Documents\Weso\Proyectos\X-Inf... More on stackoverflow.com
🌐 stackoverflow.com
database - Why can't 'npx prisma db push' find my prisma schema? - Stack Overflow
I'm trying to setup my first t3 app and I have no idea how prisma works. Trying to set up my database following a tutorial and I cannot get my prisma schema to push. I follow the tutorial precisely... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Prisma
prisma.io › home › prisma cli reference › prisma cli reference › prisma cli reference
Prisma CLI reference | Prisma Documentation
The db push command pushes the state of your Prisma schema to the database without using migrations.
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 › prototyping your schema › prototyping your schema › prototyping your schema › prototyping your schema
Prototyping your schema | Prisma Documentation
You want to replicate your schema changes in other environments without losing data. You can use db push for prototyping, but you should use migrations to commit the schema changes and apply these in your other environments.
🌐
GitHub
github.com › prisma › prisma › issues › 18412
`npx prisma db push` and `npx prisma migrate` error when there is a table that starts with `_` · Issue #18412 · prisma/prisma
March 22, 2023 - Bug description I try to keep a unified style in my database, so I specify a unique name for each table. But when using the implicit many-to-many relation, I get tables that start with _, so I have to name my utility tables with _ at the...
Author   prisma
Find elsewhere
🌐
PlanetScale
planetscale.com › guides › frameworks and orms › prisma › automatic prisma migrations
Automatic Prisma migrations - PlanetScale
1 week ago - In another terminal, use the db push command to push the schema defined in prisma/schema.prisma: npx prisma db push · Unlike the prisma migrate dev command, it will not create a migrations folder containing a SQL file with the SQL used to update ...
🌐
DEV Community
dev.to › digitaldrreamer › prisma-db-push-or-pull-stuck-1g4j
Prisma db push or pull stuck? - DEV Community
January 7, 2026 - When working with Prisma and Supabase DB, I got an issue with the Prisma CLI getting stuck during prisma db push and prisma db pull. I eventually for to know that the issue often arises when using a Supabase connection string with the pooled connection (port 6543). For example, running npx prisma ...
🌐
GitHub
github.com › prisma › prisma › discussions › 23890
npx prisma db push error after migrating from Planetscale to Neon · prisma/prisma · Discussion #23890
So, fortunately, I tried npx prisma db pull and magically resolved this issue. It completely rewrites my Prisma schema file with relations from the previous data model as follows: ... It basically added maps to the correct relations from the previous data model. And this fixed the error when I do push now.
Author   prisma
🌐
GitHub
github.com › vercel › next-forge › issues › 382
npx prisma db push -> dangerous · Issue #382 · vercel/next-forge
January 2, 2025 - Runs npx prisma db push to apply the migration to your database (CAUTION: may destroy / drop tables).
Author   vercel
🌐
MCP Servers
mcpservers.org › home › agent skills library › prisma-cli-db-push
prisma-cli-db-push | Agent Skills Library
Reference when using this Prisma feature. npx skills add https://github.com/prisma/cursor-plugin --skill prisma-cli-db-push · Download ZIPGitHub · 8 · Pushes schema changes directly to database without creating migrations.
🌐
Prisma
prisma.io › home › deploying database changes with prisma migrate › deploying database changes with prisma migrate › deploying database changes with prisma migrate › deploying database changes with prisma migrate
Deploying database changes with Prisma Migrate | Prisma Documentation
name: Deploy on: push: paths: - prisma/migrations/** branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout repo uses: actions/checkout@v3 - name: Setup Node uses: actions/setup-node@v3 - name: Install dependencies run: npm install - name: Apply all pending migrations to the database run: npx prisma migrate deploy env: DATABASE_URL: ${{ secrets.DATABASE_URL }}
🌐
Reddit
reddit.com › r/nextjs › i am using prisma with planetscale but when i use npx prisma db push i have this error . i
r/nextjs on Reddit: i am using Prisma with planetscale but when i use npx prisma db push i have this error . i
September 30, 2023 -

mastan@mastan-Lenovo-ideapad-110-15ISK:~/Desktop/tata/sas$ npx prisma db push

Environment variables loaded from .env

Prisma schema loaded from prisma/schema.prisma

Datasource "db": MySQL database "discord-clone" at "aws.connect.psdb.cloud"

Error: P1001: Can't reach database server at `aws.connect.psdb.cloud`:`3306`

Please make sure your database server is running at `aws.connect.psdb.cloud`:`3306`.