Hi @rainnfx 👋

Thank you for raising this question.

It's not a stupid question at all! Managing schema changes without data loss is a common concern. The prisma db push command is designed to quickly synchronize your Prisma schema with your database schema. However, it does not generate migration files and is best suited for prototyping in a development environment. When prisma db push detects changes that could result in data loss (e.g., adding a required field without a default value), it will prompt you to reset the database.

You should use prisma migrate commands instead of prisma db push. This command helps you create and apply migrations during development. This command helps you create and apply migrations during development.

  • Expand and Contract Pattern:

This pattern allows you to evolve your schema without downtime and data loss. It involves making non-destructive changes first (e.g., adding a nullable field) and then gradually evolving the schema.
You can read more about this pattern in the documentation.

Discussions

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
prisma migrate dev - data lost
Hi. I am trying to migrate my updated schema to my database. But when I do I get the question: We need to reset the MySQL database... All data will be lost How can I migrate without losing all my data? PrismaJoinThe official Discord server of Prisma! More on answeroverflow.com
🌐 answeroverflow.com
October 17, 2024
What is the good practice for migrations and keeping them on GitHub?
Here is the scenario, our database ... project already has a lot of online users is there a way we can update our database without resetting and how to do it? I assume it is with prisma migrations, if that is the case, should we keep the migration files on our GitHub repository ... More on answeroverflow.com
🌐 answeroverflow.com
February 10, 2025
Prisma model change without data loss
I am working on a t3 project and currently only have one database. I want to change the type of a column in a model but when trying to use db push I am asked to reset the database. After looking around and asking Chatgpt, I tried using Prisma migrate dev but I am given a similar message about ... More on answeroverflow.com
🌐 answeroverflow.com
April 19, 2023
🌐
Prisma
prisma.io › home › customizing migrations › customizing migrations › customizing migrations › customizing migrations
Customizing migrations | Prisma Documentation
Modify the generated SQL file. ... 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.
🌐
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 › 1296448016353595472
prisma migrate dev - data lost
October 17, 2024 - Hi. I am trying to migrate my updated schema to my database. But when I do I get the question: We need to reset the MySQL database... All data will be lost How can I migrate without losing all my data? PrismaJoinThe official Discord server of Prisma!
🌐
Wasp
wasp.sh › blog › 2025 › 04 › 02 › an-introduction-to-database-migrations
A Gentle Introduction to Database Migrations in Prisma with Visuals | Wasp
April 2, 2025 - Again, the main problem is the existing production data that we have in our production database. We can't just delete all the tables in our database and recreate them with the new structure. We'd lose valuable user data. We will do this migration in multiple steps to change the score format without our users noticing anything.
Find elsewhere
🌐
Build with Matija
buildwithmatija.com › blog › solving-database-drift-in-postgresql-17-with-prisma-without-losing-data
Solving Database Drift in PostgreSQL 17 With Prisma Without Losing Data | Build with Matija
January 13, 2025 - Prisma’s solution is often to reset the database: Resetting deletes all data to start fresh, which is unacceptable in most cases. Instead of resetting the database, I created a baseline migration that synchronized Prisma’s migration history ...
🌐
GitHub
github.com › prisma › prisma › discussions › 13160
How I can change data in prisma.schema, without losing data after migration? · prisma/prisma · Discussion #13160
May 5, 2022 - npx prisma migrate dev --schema prisma/schema2.prisma --name edit-form-datable --create-only · Even though the --create-only flag is used to generate migration files without applying the changes to the database immediately, it still prompts with a warning: "Do you want to continue?
Author   prisma
🌐
Prisma
prisma.io › home › prototyping your schema › prototyping your schema › prototyping your schema › prototyping your schema
Prototyping your schema | Prisma Documentation
There is no way to orchestrate schema and data migrations—if db push anticipates that changes will result in data loss, you can either accept data loss with the --accept-data-loss option or stop the process.
🌐
Answer Overflow
answeroverflow.com › m › 1338479942110941294
What is the good practice for migrations and keeping them ...
February 10, 2025 - Here is the scenario, our database will update accordingly with the project, we want to release some feature later let's use Reddit karma for example which is (I assume) only one table column added, if our project already has a lot of online users is there a way we can update our database without resetting and how to do it? I assume it is with prisma migrations, if that is the case, should we keep the migration files on our GitHub repository or are we allowed to either delete them or add them to .gitignore?
🌐
Prisma
prisma.io › home › understanding migrations › understanding migrations › understanding migrations › understanding migrations
A mental model for Prisma Migrate | Prisma Documentation
There is no way to orchestrate schema and data migrations - if prisma db push anticipates that changes will result in data loss, you can either accept data loss with the --accept-data-loss option or stop the process - there is no way to customize ...
🌐
Fig
fig.io › manual › prisma › migrate › reset
prisma migrate reset | Fig
Reset your database and apply all migrations, all data will be lost
🌐
Answer Overflow
answeroverflow.com › m › 1098050198791524443
Prisma model change without data loss - Theo's Typesafe Cult
April 19, 2023 - I am working on a t3 project and currently only have one database. I want to change the type of a column in a model but when trying to use db push I am asked to reset the database. After looking around and asking Chatgpt, I tried using Prisma migrate dev but I am given a similar message about my Prisma schema not being in sync with my migration history and am again prompted to reset the db.
🌐
Stack Overflow
stackoverflow.com › questions › 73292180 › prisma-io-erasing-data-when-migrate-prod-database › 73292595
node.js - PRISMA.IO - Erasing data when migrate prod database - Stack Overflow
You want to quickly prototype and iterate on schema design locally without the need to deploy these changes to other environments such as other developers, or staging and production environments. In a development environment, use the migrate dev command to generate and apply migrations: ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 4 node.js | Replacing DB client with Prisma keeping preserving DB structure - issue with uuid_generate_v4()
🌐
YouTube
youtube.com › watch
Simplify Database Migrations Using PRISMA MIGRATE!!! - YouTube
Learn how to use Prisma to perform Database Schema Migrations!In this video we will look at:1] Why Database migrations is important?2] What aspects to keep i...
Published   May 7, 2022
🌐
DEV Community
dev.to › this-is-learning › its-prisma-time-migrations-7pk
It's Prisma Time - Migrations - DEV Community
February 2, 2022 - How we can notice, updating our schema is not so difficult using the migrate command, unless we have to rename one or more fields. When we have to rename a field, the Prisma Migrate tool works in this way ... as you can imagine, by doing that, we'll lose our data.
🌐
RedwoodJS Community
community.redwoodjs.com › get help and help others
Views in prisma schema cause unit test scenarios to break - Get Help and Help Others - RedwoodJS Community
August 1, 2024 - Hey all, I’m using Redwood 6.6.4. I’ve got a test suite across our Redwood app that relies pretty heavily on scenarios. Recently, I used the “views” preview feature and added some db migrations with my Postgres views, and then added those views to the prisma schema.
🌐
Blog
blog.miraclesoft.com › home › simplifying database development with prisma
Simplifying Database Development with Prisma – Blog | Miracle Software Systems
April 14, 2025 - Flexibility: It supports various databases, including MySQL, PostgreSQL, and SQLite, allowing you to choose the database that suits your requirements. Migration System: Prisma’s migration system effortlessly adapts your schema over time without losing data.
🌐
Prisma
prisma.io › home › migration histories › migration histories › migration histories › migration histories
About migration histories | Prisma Documentation
As you start to customize migrations, your migration history contains information that cannot be represented in the Prisma schema. For example, you can customize a migration to mitigate data loss that would be caused by a breaking change.