1
resposta

[Bug] Problema com a migração do flyway

Nas primeiras aulas da criação do projeto, tive que alterar algumas coisas pois já passou algum tempo e houveram atualizações. Porém, com o passar do curso, acabei apagando um pedaço do arquivo que não deveria(Espero não ter sido o único a já ter feito isso rs), ao baixar novamente pelo arquivo disponibilizado, encontrei o seguinte erro: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2024-01-22T19:16:24.334-03:00 ERROR 9220 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Validate failed: Migrations have failed validation Migration checksum mismatch for migration version 2 -> Applied to database : -1809053286 -> Resolved locally : -1848389755 Either revert the changes to the migration, or run repair to update the schema history. Need more flexibility with validation rules? Learn more: https://rd.gt/3AbJUZE at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1754) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:313) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1141) ~[spring-context-6.0.0-M6.jar:6.0.0-M6] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:916) ~[spring-context-6.0.0-M6.jar:6.0.0-M6] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:592) ~[spring-context-6.0.0-M6.jar:6.0.0-M6] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.0.0-M5.jar:3.0.0-M5] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:751) ~[spring-boot-3.0.0-M5.jar:3.0.0-M5] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:442) ~[spring-boot-3.0.0-M5.jar:3.0.0-M5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) ~[spring-boot-3.0.0-M5.jar:3.0.0-M5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1323) ~[spring-boot-3.0.0-M5.jar:3.0.0-M5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-3.0.0-M5.jar:3.0.0-M5] at med.voll.api.ApiApplication.main(ApiApplication.java:10) ~[classes/:na] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:578) ~[na:na] at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-3.0.0-M5.jar:3.0.0-M5] Caused by: org.flywaydb.core.api.exception.FlywayValidateException: Validate failed: Migrations have failed validation Migration checksum mismatch for migration version 2 -> Applied to database : -1809053286 -> Resolved locally : -1848389755 Either revert the changes to the migration, or run repair to update the schema history. e ao rodar com o debug ativo, continua dando erro, oq posso fazer? já tentei colocar o spring.flyway.repair=true no arquivo application.properties mas não funcionou. Acabei excluindo o arquivo antigo, por isso não tenho como só copiar o pom.xml

1 resposta

Oi!

Tem aqui no curso como lidar com erros do flyway: https://cursos.alura.com.br/course/spring-boot-3-desenvolva-api-rest-java/task/121056