31

I've got a Flyway exception:

FlywayException: Detected failed migration to version 1.0

I looked for on documentation and forums but I didn't found what mean this exception. Please someone can tell me what can be the reasons of these exception ! Thanks

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Gwen
  • 311
  • 1
  • 3
  • 3
  • Look at this fix https://stackoverflow.com/questions/44681583/schema-boxfuse-dev-db-contains-a-failed-migration-to-version-10-the-migratio/69347777#69347777 – Ashraf Sarhan Sep 27 '21 at 13:47

2 Answers2

40

"FlywayException: Detected failed migration to version 1.0"

it means that you ran migrate before and it failed at 1.0 for some reason. You need to identify why the previous migration failed at 1.0 and solve it if you have already not done so. Once solved you need to run flyway repair to tell flyway that whatever failed is now out of the way.

Then run flyway migrate again. If it fails again, you are back on step 1. Good luck with the migration.

SudhirR
  • 760
  • 4
  • 11
  • Thanks for the answer...i finally found a basic sql error in my code...i ran again flyway as you said...and it works :) – Gwen Jul 10 '17 at 14:36
  • Saved my day !! – G.S Abhaypal Jun 07 '18 at 12:32
  • "flyway repair", my understanding is that it removed the 'failed' from schema history table. Yet part of the failed migration might already run. I had to find the line of error, comment out all lines above since they 're done, then run "flyway migrate" again, works perfectly. – Emily Jun 14 '19 at 14:13
  • 7
    How to execute flyway repair ? – Aguid Aug 05 '20 at 20:21
  • 4
    `mvn flyway:repair` in console should do. if using intelliJ you have this in maven plugins `maven -> -> plugins -> flyway -> flyway:repair` – MalliKharjuna Rao Dec 09 '21 at 20:42
27

Make

select * from your_database_name.flyway_schema_history

you will get something like this:

Query to flyway_schema_history table query to flyway_schema_history table]

Then find the entry that corresponds to the migration that is failing and delete it, it should work.

zx485
  • 28,498
  • 28
  • 50
  • 59
Isidro Vásquez
  • 271
  • 3
  • 2