Flyway 3.0 Migration Checksum mismatch

MavenFlyway

Maven Problem Overview


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?

Maven Solutions


Solution 1 - Maven

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

Solution 2 - Maven

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.

Solution 3 - Maven

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.

Solution 4 - Maven

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

Solution 5 - Maven

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 :)

Solution 6 - Maven

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."

Solution 7 - Maven

The checksum needs to be updated using the flyway repair command (run the Flyway command as stated in “Upgrade procedure” but replace “migrate” with “repair”).

I recommend you do not intrude directly to database, sql scripts, etc. It can be dangerous

Example:
./flyway repare -user=root -password=changeme -url=jdbc:mysql://localhost/mypath -table=my_flyway_schema_version_table -locations=filesystem:/mypath_sql_scripts

Solution 8 - Maven

if you are running on local db u can delete the flyway_schema_history table

Solution 9 - Maven

Invoke Flyway.repair() directly from configurations.

Add below bean to your configuration class or create a new class with @Congiguration annotation and add the below code.

    @Bean
    public FlywayMigrationStrategy repairFlyway() {
        return flyway -> {
            // repair each script's checksum
            flyway.repair();
            // before new migrations are executed
            flyway.migrate();
        };
    }

Solution 10 - Maven

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbbcooperView Question on Stackoverflow
Solution 1 - MavenAxel FontaineView Answer on Stackoverflow
Solution 2 - MaventfendallView Answer on Stackoverflow
Solution 3 - MavenPrashanthView Answer on Stackoverflow
Solution 4 - MavenaarborView Answer on Stackoverflow
Solution 5 - MavenSaifView Answer on Stackoverflow
Solution 6 - MavenmfrancisyView Answer on Stackoverflow
Solution 7 - MavenHector BarrigaView Answer on Stackoverflow
Solution 8 - MavenKumar ShanooView Answer on Stackoverflow
Solution 9 - MavenmanojView Answer on Stackoverflow
Solution 10 - MavenDenisView Answer on Stackoverflow