32

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

1

3 Answers 3

42

"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.

5
  • 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
    Commented Jul 10, 2017 at 14:36
  • Saved my day !! Commented Jun 7, 2018 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
    Commented Jun 14, 2019 at 14:13
  • 9
    How to execute flyway repair ?
    – Aguid
    Commented Aug 5, 2020 at 20:21
  • 5
    mvn flyway:repair in console should do. if using intelliJ you have this in maven plugins maven -> <service name> -> plugins -> flyway -> flyway:repair Commented Dec 9, 2021 at 20:42
28

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.

1
  • 2
    Note, that this table might have a different name depending on the configuration
    – Andronicus
    Commented Apr 20, 2020 at 13:56
0

You can also do it by manual update by changing value of column success from 0 to 1 in corresponding row. Of course it cause that the corresponding script will not execute again, so You have to make sure that all the changes applied to database. I'm not recommend it to do on production. It shouldn't happen on production rather on developing environments.

Not the answer you're looking for? Browse other questions tagged or ask your own question.