Are you sure this is not caused by your usage of dotenv as the first command, which wraps prisma and "swallows" all the options with --?
I think you need to do -- --create-only in this case, possible?

🌐
Prisma
prisma.io › home › development and production › development and production › development and production › development and production
Development and production | Prisma Documentation
The --create-only command allows you to create a migration without applying it: ... To apply the edited migration, run prisma migrate dev again.
Discussions

`migrate dev --create-only` doesn't work in the first time on an existing database
Bug description I want to try prisma as a migrate tool in an existing non-prisma project. so I've run prisma db pull on an existing database and got the schema.prisma file, then I want to make ... More on github.com
🌐 github.com
7
March 11, 2022
npx prisma migrate dev --create-only : not working as intended in documentations
Bug description Working with prisma 5.6.0 on dev environment intended behaviour is first create migration and then apply it on the dev environment. npx prisma migrate dev --create-only command used... More on github.com
🌐 github.com
1
1
December 5, 2023
`npx prisma migrate dev --create-only` actually resets database
It tells you it will do it: ... √ Drift detected: Your database schema is not in sync with your migration history. [+] Added tables - Buyer - BuyerGroup [*] Changed the `Buyer` table [+] Added fore... More on github.com
🌐 github.com
20
July 4, 2021
node.js - Make a change to the database with Prisma.js without having to reset the whole thing - Stack Overflow
How can make a change to the database with Prisma.js without having to reset the whole thing? if I have used this command npx prisma migrate dev --name role-makeOptional-NormalizedName I will lose... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Prisma
prisma.io › home › dev › dev › dev
prisma migrate dev | Create & Apply Migrations | Prisma Documentation
Prisma v7: migrate dev no longer automatically triggers prisma generate or seed scripts. Run them explicitly if needed. If a schema drift is detected while running with --create-only, you will be prompted to reset your database.
🌐
Prisma
prisma.io › home › customizing migrations › customizing migrations › customizing migrations › customizing migrations
Customizing migrations | Prisma Documentation
bunx prisma migrate dev --create-only · Modify the generated SQL file. Apply the modified SQL by running: bun · pnpm · yarn · npm · bunx prisma migrate dev · By default, renaming a field in the schema results in a migration that will: ...
🌐
GitHub
github.com › prisma › prisma › discussions › 24571
How should migration be done to Production? · prisma/prisma · Discussion #24571
In your development environment, you use prisma migrate dev --create-only to create a migration file without applying it. This command generates the migration.sql file based on the changes in your schema.prisma.
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 12272
`migrate dev --create-only` doesn't work in the first time on an existing database · Issue #12272 · prisma/prisma
March 11, 2022 - bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.Bug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.A reported bug.tech/enginesIssue for tech Engines.Issue for tech Engines.topic: drifttopic: prisma migrate dev --create-onlyCLI: prisma migrate dev --create-onlyCLI: prisma migrate dev --create-only · xiangnanscu · opened · on Mar 11, 2022 · Issue body actions · I want to try prisma as a migrate tool in an existing non-prisma project. so I've run prisma db pull on an existing database and got the schema.prisma file, then I want to make the first migrations without applying changes: npx prisma migrate dev --create-only ·
Author   prisma
🌐
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.
Find elsewhere
🌐
npm
npmjs.com › package › @shoito › prismarls
@shoito/prismarls - npm
# Create a migration with Prisma Migrate --create-only npx prisma migrate dev --create-only --name migration # Use Prismarls to add RLS settings and create policies for the specified tables npx @shoito/prismarls --schema=./prisma/schema.prisma --migrations=./prisma/migrations --currentSettingIsolation=app.company_id --currentSettingBypass=app.bypass_rls
      » npm install @shoito/prismarls
    
Published   Dec 19, 2024
Version   0.0.5
Author   shoito
🌐
GitHub
github.com › prisma › prisma › issues › 8053
`npx prisma migrate dev --create-only` actually resets database · Issue #8053 · prisma/prisma
July 4, 2021 - But in the end it is still surprising that a command that is supposed to only create a migration (file), modifies the database. ... topic: prisma migrate devCLI: prisma migrate devCLI: prisma migrate devtopic: prisma migrate dev --create-onlyCLI: prisma migrate dev --create-onlyCLI: prisma migrate dev --create-only
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 6579
`migrate dev --create-only` with empty schema but existing database schema detects drift and warns about deleting all data · Issue #6579 · prisma/prisma
April 14, 2021 - ... yes √ Name of migration ... init Prisma Migrate created the following migration without applying it 20210414181550_init You can now edit it and apply it by running prisma migrate dev. --create-only needing to reset my database, and supposedly even doing that, was unexpected. No changes on data or warnings that indicate that when using --create-only. PS C:\Users\piotr\Documents\serverless-prisma\demo> npx prisma -v Environment variables loaded from .env prisma : 2.21.1 @prisma/client : 2.21.1 Current platform : windows Query Engine : query-engine e421996c87d5f3c8f7eeadd502d4ad402c89464d (
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 27108
❗ Issue: Error P3006 when running npx prisma migrate dev --create-only after resolving migration from empty state · Issue #27108 · prisma/prisma
May 7, 2025 - ❗ Issue: Error P3006 when running npx prisma migrate dev --create-only after resolving migration from empty state#27108
Author   prisma
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.
🌐
Prisma
prisma.io › home › prisma cli reference › prisma cli reference › prisma cli reference
Prisma CLI reference | Prisma Documentation
CREATE NEW DATABASE: Local: npx ... database) Then, define your models in `prisma/schema.prisma` and run `npx prisma migrate dev` to apply your schema....
🌐
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
🌐
Answer Overflow
answeroverflow.com › m › 1342542831247560848
Migration issue in UAT - Prisma
February 21, 2025 - When you run npx prisma migrate dev --create-only on your UAT_DB_IN_LOCAL database, Prisma is detecting a mismatch between the current state of your database and the migration history.