Flyway 3.0 Migration Checksum mismatch

after upgrading Flyway Maven plugin from 2.3 to 3.0 I get:

[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:3.0:migrate (default-cli) on project xxx: org.flywaydb.core.api.FlywayException: Validate failed. Found differences between applied migrations and available migrations: Migration Checksum mismatch for migration V003__data_feed_sources_locations.sql: DB=942424992, Classpath=1117634405 -> [Help 1]

Got a similar error on some other project.

If I downgrade back to 2.3 the migration runs ok. Does this has something to do with different platform encoding for calculating checksums?

Any workaround, or better yet, proper solution?

Answers


Flyway 3.0 changed the default of validateOnMigrate to true.

This is however a good thing, as in the spirit of fail fast, errors are discovered sooner.

In your case some scripts did change since they were applied, which is what Flyway is reporting.

You have two options:

  • suppress the error by setting validateOnMigrate to false (2.3 default behavior)
  • invoke Flyway.repair() to reallign the checksums

To add to Axel Fontaine's answer:

I was able to use mvn flyway:repair but I had to point the flyway.locations config property at the folder that contains my db migration scripts. Otherwise I would get the message "Repair of metadata table xyz.schema_version not necessary. No failed migration detected." like other folks mentioned.

I used mvn -Dflyway.locations=filesystem:<project dir>/src/main/resources/db/migrations flyway:repair and I saw the checksum updated in the metadata table, fixing my problem.


First, it looks for checksum changes. These changes occur if we update migration files which are already applied to a db instance.

FlywayException: Validate failed: Migration checksum mismatch for migration version 18.2.6

-> Applied to database : 90181454

-> Resolved locally : 717386176

repair() method would fix up checksum issue by updating the flyway_schema_history table with local checksum value.

However, it would neglect updated statements in same migration file. So, new changes in same file would be neglected as there is already an entry for version in flyway_schema_history table. setValidateOnMigrate() method has no effect in this scenario. We should follow incremental approach, schema changes should be supplied through new files.


The issue happen right after I changed the V1_2__books.sql ddl file, There should be a better way to force flyway to recognize the new changes!!!

I tried to run mvn flyway:repair but it did not work, I ended up changing the schema url in the application.properties file [datasource.flyway.url] to books2

I removed the below files as well (books is my old schema name )

~ @~:rm books.mv.db 
~ @~:rm -r books.trace.db 
datasource.flyway.url=jdbc:h2:file:~/books2
datasource.flyway.username=sa
datasource.flyway.password=
datasource.flyway.driver-class-name=org.h2.Driver

I ran the application and BINGO :)


I found the easiest way to resolve this issue was to literally update the checksum in the schema table to the value flyway expected. I knew for a fact that my migration files had not changed and that the current state of the database was what it needed to be. I also did not want to spend time reading documentation and messing around with Flyway.repair() or other methods that could potentially mess things up even more. A simple sql update resolved it right away


Just wanted to add, that in order for the checksum to be updated by repair. Flyway has to have access to the directory where all the migrations are. Otherwise flyway just goes about it's business and outputs

"Repair of failed migration in metadata table xyz.schema_version not necessary. No failed migration detected."


There is yet another solution. You can drop your migration from schema_version table.


Need Your Help

can you host a private repository for your organization to use with npm?

node.js repository npm

Npm sounds like a great platform to use within an organization, curious if a private repo is possible, like with Nexus/Maven. Nothing comes up on Google :(