0

I have an app written in NextJS deployed to Vercel and spun up PostreSQL on Heroku.

Earlier I was using MySQL then changed configuration to PostgreSQL. I have deployed tables to Heroku PostgreSQL using npx prisma migrate save --schema ./prisma/schema.prisma --experimental

Now, I am facing an issue while doing npx prisma migrate up --schema ./prisma/schema.prisma --experimental

The error I get is:

Changes to be applied:

model TableA {
  id Int @default(autoincrement()) @id
  ...skipped columns...
}

model TableB {
  id Int @default(autoincrement()) @id
  ...skipped columns...
}

Checking the datasource for potential data loss...

Database Changes:

Migration                                                        Database actions  Status

20201129201149-patchfix-changed-xxxxxx-aaaaaa   statements.    
20201215212131-add-ttttttt-schema                                statements.    
20201227083423-add-postgresql-database-remote-heroku              statements.    
20201227090719-add-mysql-heroku-deployed                          statements.    
20210512203825-initial                                            statements.    

You can get the detailed db changes with yarn prisma migrate up --experimental --verbose
Or read about them here:
      ./migrations/20201129201149-patchfix-changed-xxxxxx-aaaaaa/README.md

      ./migrations/20201215212131-add-ttttttt-schema/README.md

      ./migrations/20201227083423-add-postgresql-database-remote-heroku/README.md

      ./migrations/20201227090719-add-mysql-heroku-deployed/README.md

      ./migrations/20210512203825-initial/README.md

Error: Error querying the database: Error querying the database: db error: ERROR: column "someMaskedColumnName" cannot be cast automatically to type integer
   0: sql_migration_connector::sql_database_step_applier::apply_step
           with index=0
             at migration-engine/connectors/sql-migration-connector/src/sql_database_step_applier.rs:15
   1: migration_core::api::ApplyMigration
           with migration_id="20201129201149-patchfix-changed-xxxxxx-aaaaaa"
             at migration-engine/core/src/api.rs:82

error Command failed with exit code 1.

Please help me resolve this I am unable to fix this issue since many days.

rohitpaniker
  • 695
  • 1
  • 7
  • 25
  • Did you change a type from xxx to an integer? Was your last migration from MySQL and your new one on PostgreSQL? What does it say when you run - yarn prisma migrate up --experimental --verbose – Sean W May 13 '21 at 01:07
  • @SeanW Yes, in my migrations directory there are 15 migration directories and a migrate.lock. I changed database type from MySQL to PostgreSQL in the app suddenly because I was unable to get MySQL spun up in Heroku and instead added service for PostgreSQL and changed my app to use PostgreSQL instead of MySQL, did ```prisma save``` (this worked) and ```prisma up```(this is where the error comes up half way) to reflect new changes. Have tried your suggestion but same error comes up – rohitpaniker May 13 '21 at 07:36
  • @SeanW yes throughout the app development there's couple of sql data-type changes from DateTime to Int – rohitpaniker May 13 '21 at 07:37
  • It's hard to debug since we cannot read the errors or see the column name that failed. My guess, based on what you are saying is that the db has date entries and you are telling the migration to use int and the two are not interchangeable. – Sean W May 13 '21 at 08:19
  • @SeanW I am guessing it is caused by one of the schema migration out of all migrations being applied one after another, I was thinking of deleting all migrations and applying just one. Any idea how that can be done? – rohitpaniker May 13 '21 at 08:23
  • I'd create a backup of you migrations and db data. Test the import it to validate the backups are good. Manually import your tables without data to postgres (or with), you can delete the migration tables and files in your code. - then resync prisma. During resycn prisma will likely say things are out of sync and prompt warnings that will likely result in data loss so you will need to import your data backup. – Sean W May 13 '21 at 18:14

0 Answers0