Migration issue in UAT

i am just using command like "npx prisma migrate deploy" to deploy migration files... i have 34 migration done.... but now what i have done is like take a copy of databse ... and restored it locally.... now my UAT databse is in my local postgresDB...named as "UAT_DB_IN_LOCAL" (database having same data in ALL table as UAT) ------- i have added in schema file model stu { id int? name string? } now i am using command like .... npx prisma migrate dev --create-only its now coming to 28th migration correctly and for 29th migration its saying like below The migration 20241021113752_dcs_mangement was modified after it was applied. ? We need to reset the "public" schema at "localhost:5432" Do you want to continue? All data will be lost. » (y/N) i know that i have added all migration in UAT database sucessfully...... also there are 34 files presenr and 34 rows in prisma_migration table ..... then why i am getting error..... if i make different db name as "UAT_LOCAL_DB_TEST" (no data is restored empty db) and apply there its making migration.sql file correctly.... and if i use on "UAT_DB_IN_LOCAL" "npx prisma migrate deploy" then tables are created goodly...... -------------------------------------------------------------------------------- why i cant "npx prisma migrate dev --create-only" use it "UAT_DB_IN_LOCAL" ...........and create migration file?????
7 Replies
Prisma AI Help
You chose to compile with the bot. One moment while I piece together your answer… Based on the information provided in the knowledge sources, I can explain why you're encountering this issue and suggest a possible solution. The problem you're experiencing is related to how Prisma Migrate detects schema drift and handles existing databases. When you run npx prisma migrate dev --create-only on your UAT_DB_IN_LOCAL database, Prisma is detecting a mismatch between the current state of your database and the migration history. This behavior is described in the Github Issue #6579, where it's mentioned that --create-only can still trigger a database reset warning, even when it's not supposed to modify the database. The reason you're able to create the migration file on an empty database (UAT_LOCAL_DB_TEST) is that there's no existing schema to conflict with the new changes. To resolve this issue and create your migration file without resetting your database, you can try the following approach: 1. Use the baselining feature of Prisma Migrate. This is designed for situations where you have an existing database that you want to start managing with Prisma Migrate. 2. Follow the steps outlined in the Prisma documentation on baselining: a. Create a migration for your current database schema:
npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > prisma/migrations/0_init/migration.sql

npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > prisma/migrations/0_init/migration.sql

b. Edit the migration name and timestamp in the file name and contents. c. Mark the migration as applied:
npx prisma migrate resolve --applied 0_init

npx prisma migrate resolve --applied 0_init

3. After baselining, you should be able to create new migrations using npx prisma migrate dev --create-only without getting the reset warning. It's worth noting that this issue has been recognized by the Prisma team, and they are working on improving the behavior of --create-only to be less confu sing and more intuitive, as mentioned in the Github Issue #8053. If you continue to face issues after trying this approach, you might want to consider using prisma db push for development and prisma migrate deploy for production, as suggested in some of the discussions in the knowledge sources. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
hari_narayan
hari_narayanOP2w ago
{ "_prisma_migrations": [ { "finished_at" : "2024-09-25T06:28:05.872Z", "migration_name" : "20240925062535_email", "started_at" : "2024-09-25T06:28:05.172Z", "applied_steps_count" : 1 }, { "finished_at" : "2024-09-25T06:28:05.872Z", "migration_name" : "20241021113752_dcs_mangement", "started_at" : "2024-10-24T06:28:05.172Z", "applied_steps_count" : 1 }, { "finished_at" : "2024-10-24T13:08:21.393Z", "migration_name" : "20241024130448_extra_column_removed", "started_at" : "2024-10-24T13:08:20.747Z", "applied_steps_count" : 1 } ]} { "finished_at" : "2024-09-25T06:28:05.872Z", "migration_name" : "20241021113752_dcs_mangement", "started_at" : "2024-10-24T06:28:05.172Z", "applied_steps_count" : 1 }, upper causing issue npx prisma migrate resolve --applied 20241021113752_client_onbording_and_docs_mangementError: P3008 The migration 20241021113752_dcs_mangement is already recorded as applied in the database. but then also problem persisted....... i m getting same error The migration 20241021113752_dcs_mangement was modified after it was applied. ? We need to reset the "public" schema at "localhost:5432" Do you want to continue? All data will be lost. » (y/N) see i dont wnat to loose data i think prisma cli got some issues..... or git...
hari_narayan
hari_narayanOP2w ago
https://echobind.com/post/make-prisma-ignore-a-migration-change this is possible solution i have got i have used it in windows with Get-FileHash -Algorithm SHA256 prisma/migrations/20241021113752_dcs_mangement/migration.sql and then i have updated checkSUm in db but i dont know why it worked..... and now due to this my my migration goes down in _prisma_migration table........ i think upper is temporary thing...... i want some concreate solution please.... so that my migration sequence would not disturb and ...alll
Echobind
Make Prisma Ignore a Migration Change
How to avoid resetting your database when you need to change a Prisma migration after it has been run.
hari_narayan
hari_narayanOP2w ago
yes i know that its due to checksum my file content and checkSum has relation.......... ...... but then i have just removed one line and again added there..... chnges to file will chang checkSum..... but my production checksum should work in my UAT..... but its now taking on next migration file...... i am also getting different checksum which are not maching to my db but still everything is working?? so i think in prisma cli there may be something which will ignore the migration while "npx prisma migrate dev --create-only" so that if neare about shA checksum found ignore it and move forwrd there may i think possibility of squensing of migration depends in checksome.... dont know..... can anyone know it in depth
Nurul
Nurul2w ago
so i think in prisma cli there may be something which will ignore the migration
Perhaps you are looking for migrate resolve command?
Prisma CLI reference | Prisma Documentation
This page gives an overview of all available Prisma CLI commands, explains their options and shows numerous usage examples.
hari_narayan
hari_narayanOP2w ago
what i have lern about checksum ------ git config --global core.autocrlf it should be true..... for that worspce of git...... while cloning repo aslo never chage encoding of migration/XXXX/migration.sql files ----- so that checksum created consistence...................... also i want to know about what is encoding of prisma migration.sql??
Nurul
Nurul2w ago
I think it is UTF-8

Did you find this page helpful?