You can use the --create-only option to generate the migration file without applying it to the database. So the command will look like this:

npx prisma migrate dev --create-only

You can find more details in the reference for Prisma Migrate in the docs.

🌐
Prisma
prisma.io › home › customizing migrations › customizing migrations › customizing migrations › customizing migrations
Customizing migrations | Prisma Documentation
bunx prisma migrate dev --name rename-migration --create-only · Edit the draft migration as shown, changing DROP / DELETE to a single RENAME COLUMN: Before · After · migration.sql · ALTER TABLE "Profile" DROP COLUMN "biograpy", ADD COLUMN "biography" TEXT NOT NULL; Save and apply the migration: bun ·
🌐
Prisma
prisma.io › home › development and production › development and production › development and production › development and production
Development and production | Prisma Documentation
You want to rename a field (by ... Language - such as a stored procedure or a trigger. The --create-only command allows you to create a migration without applying it:...
Discussions

npx prisma migrate dev --create-only
Bug description so this --create-only is not working and it still asks for wiping the data How to reproduce by running "npx prisma migrate dev --create-only" this cmd Expected behavior No response ... More on github.com
🌐 github.com
7
March 6, 2023
how to generate a migration file with prisma - Stack Overflow
I tried this in the repository's prisma folder npx prisma migrate dev --name add_finance_tables but it shows this in the terminal ** Environment variables loaded from .env Prisma schema loaded from More on stackoverflow.com
🌐 stackoverflow.com
`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
Running `prisma migrate dev --create-only` actually applies previous (non-deployed) migrations
Bug description Imagine a situation where you are iterating on your schema, and using the following command to create the migration files without actually applying any of them. prisma migrate dev --create-only Suppose you initially run i... More on github.com
🌐 github.com
21
January 15, 2022
🌐
GitHub
github.com › prisma › prisma › issues › 18236
npx prisma migrate dev --create-only · Issue #18236 · prisma/prisma
March 6, 2023 - Bug description so this --create-only is not working and it still asks for wiping the data How to reproduce by running "npx prisma migrate dev --create-only" this cmd Expected behavior No response Prisma information model ui_account { id...
Author   prisma
🌐
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.
🌐
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
Find elsewhere
🌐
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 - npx prisma migrate dev --create-only · the docs says · The --create-only command allows you to create a migration without applying it · but when I do so, it says · Drift detected: Your database schema is not in sync with your migration history. ...
Author   prisma
🌐
LogRocket
blog.logrocket.com › home › effortless database schema migration with prisma
Effortless database schema migration with Prisma - LogRocket Blog
June 4, 2024 - There are 1 rows in this table, it is not possible to execute this step. You can use prisma migrate dev --create-only to create the migration file, and manually modify it to address the underlying issue(s).
🌐
GitHub
github.com › prisma › prisma › issues › 11184
Running `prisma migrate dev --create-only` actually applies previous (non-deployed) migrations · Issue #11184 · prisma/prisma
January 15, 2022 - Bug description Imagine a situation where you are iterating on your schema, and using the following command to create the migration files without actually applying any of them. prisma migrate dev --create-only Suppose you initially run i...
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
Therefore, either re-order them or move constraint creation to the last step after all tables are created, so you won't face can't create constraint errors ... Review the database schema to ensure the migration leads to the desired end-state (for example, by comparing the schema to the production database). The new migration history and the database schema should now be in sync with your Prisma schema.
🌐
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.
Author   prisma
🌐
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
🌐
Prisma
prisma.io › home › prisma cli reference › prisma cli reference › prisma cli reference
Prisma CLI reference | Prisma Documentation
If a schema drift is detected while running prisma migrate dev using --create-only, you will be prompted to reset your database.
🌐
Daily Dev Tips
daily-dev-tips.com › posts › managing-migrations-in-prisma-add-rename-columns
Managing migrations in Prisma (Add/Rename columns)
January 15, 2022 - And that is caused because Prisma does not handle renames. This makes sense as they can’t identify whether we renamed a column or removed it and added a new one. We can run the migration with a -create-only flag to solve this use case.
🌐
Prisma
prisma.io › blog › prisma-migrate-ga-b5eno5g08d0b
Prisma Migrate is Production Ready - Hassle-Free Database Migrations
March 16, 2021 - Run prisma migrate dev --create-only to create the SQL migration without applying it.
🌐
Prisma
prisma.io › home › understanding migrations › understanding migrations › understanding migrations › understanding migrations
A mental model for Prisma Migrate | Prisma Documentation
The pieces of state used to track the state of a migration are the same as the ones described in how Prisma Migrate tracks the migration state section. You can customize migrations before you apply them to the database using the --create-only flag.