Reputation: 1102
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?
Upvotes: 67
Views: 138798
Reputation: 1
If you're working with a local database and you encounter a checksum mismatch error, you can delete the rows from the Flyway schema history table starting from the version that is causing the mismatch. After that, you can rerun the migrations and Flyway will apply the migrations again and generate new checksums.
Upvotes: 0
Reputation: 3761
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();
};
}
Upvotes: 2
Reputation: 35169
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:
Flyway.repair()
to reallign the checksumsReference
Flyway Repair
Upvotes: 116
Reputation: 135
if you are running on local db u can delete the flyway_schema_history table
Upvotes: 1
Reputation: 29
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
Upvotes: 1
Reputation: 11
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."
Upvotes: 1
Reputation: 283
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.
Upvotes: 12
Reputation: 1534
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
Upvotes: 9
Reputation: 3707
There is yet another solution. You can drop your migration from schema_version table.
Upvotes: -4
Reputation: 261
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.
Upvotes: 24
Reputation: 2066
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 :)
Upvotes: 2