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?
4 Replies
RaphaelEtim
RaphaelEtim•5d ago
Hi @Josef Henryson Did you recently make any changes to your Prisma schema, such as removing fields or altering primary keys? Also, can you confirm you this question when you run npx prisma migrate dev?
Josef Henryson
Josef Henryson•5d ago
Yes I added a relation between two new fields in two types. But should this not be possible without losing all the data? I also tried to remove all migration posts from the DB and all the migration files to make a new clean migrate, but I still got the same message. I even tried prisma db pull before migrate without success.
RaphaelEtim
RaphaelEtim•5d ago
Can you try using Expand and Contract pattern to evolve the schema without downtime?
Customizing migrations | Prisma Documentation
How to edit a migration file before applying it to avoid data loss in production.
Josef Henryson
Josef Henryson•4d ago
I will check it out. Thanks. Is it possible to reset all this in some way? I tried to delete all migration posts from DB and all the migration files, made a prisma db pull and then tried to make an initial migrate again. But it still wants to reset my database. I get this message although I deleted all migration history: Drift detected: Your database schema is not in sync with your migration history. Hmm, I think I managed to solve it finally. I repeated the above steps: delete prisma_migrations in db, delete files, db pull, then an init migrate and I got the message my DB schema is in sync. Then I added my new fileds and a relation and made a new migrate and now I got a green message 😄
Want results from more Discord servers?
Add your server