Scrivio Interview library
DebuggingFoundations6 min read · updated 12 November 2026

Startup fails with 'Validate failed: Migration checksum mismatch for migration version 3'. What happened and what should you do?

Someone changed the file V3 after it had already been applied to this database, so the checksum Flyway calculates from the file no longer matches the checksum stored in flyway_schema_history, and Flyway refuses to start. The rule is never to edit an applied migration: put the original file back and add the change as a new migration. Only if the edit was harmless, such as a comment, and the team agrees, do we run flyway repair to store the new checksum, after finding out which environments ran which version.

Why this question is asked

This error usually appears on a Monday morning: the build is green, the deployment starts, and the application dies at startup with a message about version 3. It is a guard doing its job, but it is also a sign that the team's migration history has started to diverge between environments, which is a much bigger problem than one failed start. Interviewers ask about it because the quick fix, running repair, is often the wrong one. In this answer, we will see how Flyway computes and checks checksums, reproduce the error, work out what really happened, and then decide between restoring the file, adding a new migration and running repair.

1How Flyway Uses Checksums

When Flyway applies a versioned migration, it calculates a checksum, a number derived from the content of the file, and stores it in the checksum column of flyway_schema_history. A checksum is like a fingerprint: if even one character of the script changes, the number changes too.

Every time Flyway runs migrate, it first validates. For every migration recorded as applied, it recalculates the checksum of the file now on the classpath and compares the two. Spring Boot runs migrate at startup with validation turned on by default, so a mismatch stops the application before it can talk to a schema that may not be what the code expects. The point is not to protect the file; it is to make sure the scripts in source control still describe what was actually done to the database.

2Reproducing the Error

Imagine V3 created an index and was applied to staging and production last month. A developer then 'improved' it in place.

Java
-- V3__index_order_customer.sql as it was applied
CREATE INDEX idx_order_customer ON orders (customer_id);
-- V3__index_order_customer.sql after the edit
CREATE INDEX idx_order_customer ON orders (customer_id, created_at);
-- Startup on production:
-- Validate failed: Migrations have failed validation
-- Migration checksum mismatch for migration version 3
-- -> Applied to database : 1408123771
-- -> Resolved locally : -1032200114

Notice what the edit did and did not do. Production still has the old single-column index, because V3 will never run there again. A brand new environment, though, would run the edited V3 and get the two-column index. Without the checksum check, the two environments would silently differ, and a query plan that works in tests would behave differently in production.

3Finding Out What Really Happened

Before fixing anything, we need two facts: what changed in the file and which databases ran which version. The first comes from source control: git log -p on the file shows the edit, who made it and why. The second comes from each environment's history table.

SQL
SELECT version, checksum, installed_on FROM flyway_schema_history WHERE version = '3';
-- production: 3 | 1408123771 | 2026-10-02 (old file)
-- staging: 3 | 1408123771 | 2026-09-30 (old file)
-- dev-anna: 3 | -1032200114 | 2026-11-03 (new file)

Now the picture is clear. Production and staging ran the original script, while one developer database, created after the edit, ran the new one. If we only look at the failing environment, we might miss that others have already diverged. It also matters whether the edit was cosmetic, such as fixing a comment or whitespace, or a real change to the schema, because the two need different fixes.

4Fix 1: Restore the File and Add a New Migration

For a real schema change, the right fix is to put V3 back exactly as it was applied and move the change into a new migration with the next version.

SQL
-- V3__index_order_customer.sql: restored to the applied content (checksum matches again)
CREATE INDEX idx_order_customer ON orders (customer_id);
-- V12__widen_order_customer_index.sql: the change, as a new step
DROP INDEX IF EXISTS idx_order_customer;
CREATE INDEX idx_order_customer ON orders (customer_id, created_at);
Step throughDeciding how to fix a checksum mismatch
  1. Compare the file with git historywhat exactly changed?
  2. Query flyway_schema_history in each environmentwhich content ran where?
  3. Does the edit change the schema?
    YesRestore V3, add a new migrationNoConsider repair
  4. Is the team agreed and every environment checked?
    YesRun flyway repairNoRestore the original file instead

4 steps in order. Play them, or step through them one at a time.

Every environment now follows the same path: old databases run V12 on their next deploy, new databases run V3 and then V12, and they all end with the same index. The developer database that ran the edited V3 is the odd one out; since it is disposable, the simplest fix is to drop and recreate it. On a large production table we would of course use CREATE INDEX CONCURRENTLY in its own non-transactional migration, but the principle is the same: a change is always a new step.

5Fix 2: Run Repair for a Harmless Edit

If the edit really was harmless, for example a corrected comment, and every environment ran the same statements, we can accept the new file as the truth. flyway repair recalculates the checksums of applied migrations and writes the new values into the history table. It also removes entries of failed migrations on databases without transactional DDL.

YAML
flyway -url=jdbc:postgresql://db/prod -user=migrator repair
# Repaired migration checksum for version 3 (1408123771 -> -1032200114)
# Successfully repaired schema history table

Repair is a deliberate, recorded decision, not a way to make an error go away. It should be approved, run once per environment by a person or a pipeline job, and noted in the change log. Spring Boot does not run repair on its own; teams sometimes define a FlywayMigrationStrategy bean that calls repair() before migrate(), but doing that automatically in production disables the very check that caught the problem, so we avoid it. Restoring the original file is often just as easy, even for a comment change, and needs no database action at all.

6Preventing It Next Time

The best protection is to catch the edit before it merges. A CI step that runs flyway validate against a database migrated from the main branch fails any pull request that modifies an applied script. Some teams also add a simple check that rejects changes to existing files under db/migration, allowing only new files. Together with a short rule in the contribution guide, never edit an applied migration, this turns a production startup failure into a red build.

7Follow-up questions

Why does Flyway not just apply the new version of V3?

Because version 3 is already recorded as applied, and Flyway never runs a versioned migration twice. It has no way to know how to turn the old result into the new one; only a new migration can describe that step.

Can I turn validation off with validate-on-migrate=false?

Technically yes, but it hides divergence between environments instead of fixing it. The application would start, and the edited migration would still only affect new databases. It is better to keep validation on and fix the file or the history explicitly.

What if the file was changed only by line endings or encoding?

Then the content is the same for the database, but the checksum may or may not differ depending on how your Flyway version normalises the file. The fix is to restore the original bytes from git and configure the repository, for example with a .gitattributes rule, so SQL files keep consistent line endings.

8Conclusion

In this answer, we saw that a checksum mismatch means an applied migration was edited after it ran, so the file no longer describes what happened to the database. We compared the file with git history and the history tables of each environment, then restored the original file and added the change as a new migration. Repair is only for harmless, agreed edits, run deliberately, and a CI validate step prevents the problem from reaching production.

What to say in the interviewAbout 80 seconds aloud

Open with

The error means migration version 3 was edited after it was applied. Flyway stores a checksum of each applied script in flyway_schema_history and, before migrating, recalculates it from the file on the classpath.

Then, if they want more

They no longer match, so Flyway stops startup, because the scripts in the repository no longer describe what was done to this database.

My first step is to find out what changed and where: git log on the file shows the edit, and querying the history table in each environment shows which databases ran the old content and which ran the new one.

If the edit is a real schema change, I restore V3 to exactly what was applied and put the change into a new migration with the next version, so old and new databases converge on the same schema; any disposable database that ran the edited file gets recreated.

If the edit was harmless, like a comment, and the team agrees, I can run flyway repair once per environment to store the new checksum, as a recorded decision rather than an automatic step, and I would not wire repair into application startup.

To prevent it, I add flyway validate to CI against a database migrated from main, and the rule that applied migrations are never edited.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Startup fails with 'Validate failed: Migration checksum mismatch for migration version...": https://scrivio-interview-library.netlify.app/databases/schema-migration/8d6b062334/