database migration error

when I updated prisma, it needs to do db migration, but every time it needs to erease everything, is there a way that only update what has been changed instead of recreate the whole db? Environment variables loaded from .env Prisma schema loaded from ../db/schema.prisma Datasource "db": PostgreSQL database "postgres", schema "public" at "xx.xx.xx.xx:5432" - The migration 20240514212711_dev failed. - Drift detected: Your database schema is not in sync with your migration history. The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database. It should be understood as the set of changes to get from the expected schema to the actual schema. [] Changed the User table [] Altered column credits (default changed from Some(Value(Int(3))) to Some(Value(Int(1)))) ? We need to reset the "public" schema at "xx.xx.xx.xx:5432" Do you want to continue? All data will be lost. ? (y/N) @miho @Vinny (@Wasp)
5 Replies
kapa.ai
kapa.ai6mo ago
Hi @terrence. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- When you update Prisma and there are changes in your schema, you need to run a database migration. However, if the migration tries to recreate all tables instead of just updating the changed parts, it might be due to the way Prisma handles migrations between different versions. In one of the Github issues (https://github.com/wasp-lang/wasp/issues/359) related to Wasp, a contributor mentioned that when updating Prisma from v2 to v3, running db migrate-dev with existing migrations seemed to ignore them and tried to recreate them all as new migrations. This is because the underlying SQL changes a bit between versions. To avoid losing data, you might want to look for a migration guide that explains the recommended procedure for updating from your current Prisma version to the new one. For example, Prisma provides an upgrade guide (https://www.prisma.io/docs/guides/upgrade-guides/upgrading-versions/upgrading-to-prisma-3) for moving from v2 to v3. If you're still having issues, it might be helpful to ask for assistance in the Prisma community, such as their Slack channel, as suggested by a contributor in the same Github issue. Remember, before running any migration that could potentially erase data, always make sure to back up your database. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @terrence, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho6mo ago
This is just how migrations and databases work when you change the default value of a field. It has drop everything to make it the new default 🤷🏻‍♂️
martinsos
martinsos6mo ago
Yeah, so it won't be any time when you update your Prisma schema, it will happen only when you do such changes that require dropping everything.
wardbox
wardbox6mo ago
can't you modify the migration file manually to do whatever change needs to be done? something like ALTER TABLE "User" ALTER COLUMN "credits" SET DEFAULT 1;
martinsos
martinsos6mo ago
Yeah true! Some of the changes do require data migrations though, not just schema migrations. But yeah actually changing default value doesn't sound like it would require dropping any data now that I think of it.
Want results from more Discord servers?
Add your server