Flyway "Detected resolved migration not applied" (Out of Order)
Flyway found a migration with a version lower than ones already applied, but it was never run. By default Flyway will not insert an out-of-order migration into history and fails validation. This is a versioning/ordering issue.
What this error means
flyway migrate/validate fails reporting a resolved migration that is not applied, naming a version below the current schema version. It happens when a branch adds a lower-numbered migration after higher ones merged.
ERROR: Validate failed: Detected resolved migration not applied to
database: 2.3. To allow executing this migration, set -outOfOrder=true.Common causes
A lower-version migration merged late
Two branches created migrations; the lower-numbered one merged after the higher-numbered one already ran, leaving a gap Flyway will not fill by default.
Versions assigned out of sequence
Manual version numbering produced a new migration below the current schema version, which Flyway treats as out of order.
How to fix it
Renumber the migration to the next version
The cleanest fix is to give the late migration a version above the current head so history stays linear.
# rename V2.3__... to the next free version above current head
git mv sql/V2.3__add_index.sql sql/V2.5__add_index.sqlAllow out-of-order application deliberately
If you intend to support inserting older migrations, enable outOfOrder so Flyway applies the gap.
flyway migrate -outOfOrder=trueHow to prevent it
- Assign migration versions in strict increasing order; renumber late ones.
- Decide once whether
outOfOrderis enabled and apply it everywhere. - Run
flyway validatein CI to catch ordering gaps early.