エラー内容
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Found more than one migration with version 1.0.0
Offenders:
-> /プロジェクトの配置ディレクトリパス/プロジェクト名/target/classes/db/migration/V1.0.0__users.sql (SQL)
-> /プロジェクトの配置ディレクトリパス/プロジェクト名/target/classes/db/migration/V1.0.0__books.sql (SQL)
エラー原因
マイグレーションのファイルのバージョン衝突が起きていることが原因。
バージョンが同じだと、ファイル名が違う場合でも、エラーが発生する。
ファイル名が違う場合でも、起きるエラーが起きる組み合わせ
- V1.0.0__users.sql
- V1.0.0__books.sql
解決方法
バージョン名をそれぞれ、違うものにする。
例
- V1.0.0__users.sql
- V1.0.1__books.sql
なぜ違うファイル名でも、バージョンが同じだと、衝突エラーが起きるの?
Flywayは、バージョンで、マイグレーションの実行順序を決めていて、バージョンが同じだと、どのファイルをどの順序で、実行すればいいか分からなるからです。