80

We are using flyway to manage database schema version and we are facing a problem. Since we work as a team and use git as our source code management, there would be some cases that different people update database schema on their own local repo. If that happens, we will get

Detected resolved migration not applied to database: 2016.03.17.16.46"

The time "2016.03.17.16.46" was added by another person and I have already applied some timestamp later than that time. If that happens, we have to clean all database tables and create them again. We have tried to set false on validateOnMigrate and did flywayClean, but nothing help. Is there another way to change that?

Kariem
  • 4,398
  • 3
  • 44
  • 73
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523

8 Answers8

95

The migration option outOfOrder is your friend here. Set it to true to allow inserting those migrations after the fact.

On the command line, run:

flyway -outOfOrder=true migrate

Or if you use the Maven plugin:

mvn -Dflyway.outOfOrder=true flyway:migrate
sleske
  • 81,358
  • 34
  • 189
  • 227
Axel Fontaine
  • 34,542
  • 16
  • 106
  • 137
41

I faced similar problem when switching from one git branch to another and tried to run flyway:migrate. For example when I was on branch 'release_4.6.0' I didn't have migrations on my local machine from branch 'release_4.7.0' so I received next error FlywayException: Validate failed: Detected applied migration not resolved locally. The solution that worked for me is to set ignoreMissingMigrations flyway option to true. In maven it looks like

flyway:migrate -Dflyway.ignoreMissingMigrations=true

Maybe it's not an answer for this question, but it can be helpful for those who faced the same problem as me.

Here you can find more details: https://flywaydb.org/documentation/configuration/parameters/ignoreMissingMigrations

catch22
  • 1,564
  • 1
  • 18
  • 41
Alex
  • 580
  • 5
  • 8
  • Worked for me, but looks like there is some conceptual difference in how migration work in other frameworks and in flyway. – Manish Apr 29 '20 at 14:16
  • 1
    Looks like this config parameter has been deprecated and is going to be replaced with `ignoreMigrationPatterns` in the most recent versions of Flyway (see doc here: https://flywaydb.org/documentation/configuration/parameters/ignoreMigrationPatterns). Some of the functionality will only be available in the paid version Flyway Teams. – msilb Aug 05 '22 at 09:06
11

You can also put it in your application.properties file if you want to apply the migrations when starting up the app:

spring.flyway.out-of-order=true
azevik
  • 141
  • 1
  • 4
9

just add spring.flyway.ignore-missing-migrations=true to your properties file if you are using spring-boot.

This will ignore previous migrations.

Assafs
  • 3,257
  • 4
  • 26
  • 39
Harsh
  • 193
  • 1
  • 2
  • 8
1

outOfOrder did not fix the problem for us.
Two migrations slipped into one deployment before it got removed. So we added those migrations back in and undid the changes in another migration.
Worked

Piratenlulatsch
  • 75
  • 1
  • 2
  • 10
1

Since spring.flyway.ignore-missing-migrations=true became deprecated. According to the docs I advise using spring.flyway.ignore-migration-patterns=*:missing. Or in the yaml:

spring:
  flyway:
    ignore-migration-patterns:
      - "*:missing"
NickEm
  • 41
  • 3
0

In my case, I just renamed my migration file to some other name and then renamed it back – just to update modification date of the file. And it worked.

nikiforovpizza
  • 487
  • 1
  • 7
  • 13
0

In my case, there was existing a row with version 319 in database and the correponding file for 319 was renamed do 330, so the database registry could not find the corresponding file. Deleting the row from database solved the problem.