Flyway 3.0 Migration Checksum mismatch

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


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

Reference
Flyway Repair


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.


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.

Tags:

Maven

Flyway