question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma migrate - always reporting Data loss / migration file changed even with simple field addition

See original GitHub issue

Say I have a scheme (you already have a copy of my schema for https://github.com/prisma/prisma/issues/4748).

Adding a simple field like status Int @default(0) then running migrate. It reports:

image

I can assure you those migration files have not been manually changed since they were applied. This happens without fail for me.

There is no way for me to be able think about using this in production (or even alpha testing) with simple fields being added causing a DB reset.

How to reproduce

Have a scheme (use my example one if needs be as this is the one I’ve used) and without making any changes, run:

1: npx prisma migrate dev --create-only --preview-feature 2: npx prisma migrate dev --preview-feature

Let it apply the migrations, then add the status field as above to the model Arc in my schema. Then run the above commands again. It will complain with the error in the screenshot.

Environment & setup

  • OS: Windows
  • Database: MySQL 8.0
  • Node.js version: 12
  • Prisma version:
@prisma/cli          : 2.14.0
@prisma/client       : 2.14.0
Current platform     : windows
Query Engine         : query-engine 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at ..\..\..\..\node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine     : migration-engine-cli 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at ..\..\..\..\node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at ..\..\..\..\node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary        : prisma-fmt 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at ..\..\..\..\node_modules\@prisma\engines\prisma-fmt-windows.exe)
Studio               : 0.332.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
webnoobcommented, Feb 22, 2021

Ok - good to know. It’s not holding up my workflow at the moment so I’ll stay on latest so I can easily test for you guys. Just hit me up when you need some info! 😃

p.s Appreciate all your work 🎉

2reactions
webnoobcommented, Mar 11, 2021

This issue seems to have been resolved in 2.18.0. I added one prop against my Book model and the generated SQL was:

-- AlterTable
ALTER TABLE `book` ADD COLUMN     `randomField` VARCHAR(191);

No foreign keys being dropped or recreated and no data loss warnings (as I would expect with a simple change like this) 🥳

Thanks for your hard work @tomhoule and @Jolg42

Update 2.18.0 - the one update to rule them all!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migration troubleshooting in development - Prisma
This guide describes how to resolve issues with Prisma Migrate in a development environment, which often involves resetting your database.
Read more >
Command Line Interface | RedwoodJS Docs
Appends a DataMigration model to schema.prisma for tracking which data migrations have already run. Creates a DB migration using yarn redwood prisma migrate...
Read more >
How To Build a GraphQL API with Node.js, Prisma, Docker ...
Step 5 — Defining the Data Model with Prisma Migrate ... Next, create a file database.js in your project src and add the...
Read more >
How To Build a REST API with Prisma and PostgreSQL
Prisma Migrate : A powerful data modeling and migration system. ... The last thing to do is to add a tsconfig.json file to...
Read more >
Jokes App Tutorial - Remix
Choose Remix App Server if you're unsure; it's easy to change deployment ... you can always delete the prisma/dev.db file and run npx...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found