flyway报错Caused by: org.flywaydb.core.api.FlywayException: Validate failed: Detected failed migration

在这里插入图片描述

详情错误日志

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.3)

2022-11-01 13:56:26.099  INFO 25648 --- [           main] com.flyway.FlaywayApplication            : Starting FlaywayApplication using Java 1.8.0_71 on HYT211145187-01 with PID 25648 (G:\WorkSpace\springboot-test\flyway-test\target\classes started by 211145187 in G:\WorkSpace\springboot-test)
2022-11-01 13:56:26.102  INFO 25648 --- [           main] com.flyway.FlaywayApplication            : No active profile set, falling back to default profiles: default
2022-11-01 13:56:27.276  INFO 25648 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8015 (http)
2022-11-01 13:56:27.312  INFO 25648 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-11-01 13:56:27.312  INFO 25648 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-11-01 13:56:27.401  INFO 25648 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-11-01 13:56:27.401  INFO 25648 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1249 ms
2022-11-01 13:56:27.778  INFO 25648 --- [           main] o.f.c.internal.license.VersionPrinter    : Flyway Community Edition 6.5.7 by Redgate
2022-11-01 13:56:27.784  INFO 25648 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariCP - Starting...
2022-11-01 13:56:38.112  INFO 25648 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariCP - Start completed.
2022-11-01 13:56:38.130  INFO 25648 --- [           main] o.f.c.internal.database.DatabaseFactory  : Database: jdbc:mysql://10.110.13.86:3306/flyway (MySQL 5.7)
2022-11-01 13:56:38.193  WARN 25648 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 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 java.lang.reflect.InvocationTargetException
2022-11-01 13:56:38.193  INFO 25648 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariCP - Shutdown initiated...
2022-11-01 13:56:38.197  INFO 25648 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariCP - Shutdown completed.
2022-11-01 13:56:38.200  INFO 25648 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-11-01 13:56:38.209  INFO 25648 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-11-01 13:56:38.238 ERROR 25648 --- [           main] 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]: Invocation of init method failed; nested exception is java.lang.reflect.InvocationTargetException
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.15.jar:5.3.15]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.15.jar:5.3.15]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.3.jar:2.6.3]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) [spring-boot-2.6.3.jar:2.6.3]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) [spring-boot-2.6.3.jar:2.6.3]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) [spring-boot-2.6.3.jar:2.6.3]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) [spring-boot-2.6.3.jar:2.6.3]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) [spring-boot-2.6.3.jar:2.6.3]
	at com.flyway.FlaywayApplication.main(FlaywayApplication.java:14) [classes/:na]
Caused by: java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_71]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_71]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_71]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_71]
	at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:70) ~[spring-boot-autoconfigure-2.6.3.jar:2.6.3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.15.jar:5.3.15]
	... 18 common frames omitted
Caused by: org.flywaydb.core.api.FlywayException: Validate failed: 
Detected failed migration to version 1.0 (create flyway test table)

	at org.flywaydb.core.Flyway.doValidate(Flyway.java:292) ~[flyway-core-6.5.7.jar:na]
	at org.flywaydb.core.Flyway.access$100(Flyway.java:73) ~[flyway-core-6.5.7.jar:na]
	at org.flywaydb.core.Flyway$1.execute(Flyway.java:166) ~[flyway-core-6.5.7.jar:na]
	at org.flywaydb.core.Flyway$1.execute(Flyway.java:158) ~[flyway-core-6.5.7.jar:na]
	at org.flywaydb.core.Flyway.execute(Flyway.java:527) ~[flyway-core-6.5.7.jar:na]
	at org.flywaydb.core.Flyway.migrate(Flyway.java:158) ~[flyway-core-6.5.7.jar:na]
	... 25 common frames omitted

错误原因:数据库涉及的2张表没全删掉(可能有一个表还存在情况下启动的项目),如图,我这边模拟的场景是第一次启动项目,实现第一个sql创建DDL的创建表语句,第二个sql插入一条数据的场景,但是我涉及的的2个表flyway_schema_history和flyway_test_table没删掉。

在这里插入图片描述

解决方案:这两个表都删除情况下再重新启动项目

详情请看我的博客:↓

springboot使用flyway,使用介绍、个人总结及报错场景如何修改

猜你喜欢

转载自blog.csdn.net/a924382407/article/details/127650570
今日推荐