首页 > 解决方案 > 使用 H2 的 Flyway 迁移失败

问题描述

我的 Spring Boot 应用程序使用 H2 进行测试,我还添加了 flyway maven 插件和依赖项(flyway-core 和 flyway-spring-test)。这是我的应用程序-test.properties:

spring.datasource.url=jdbc:h2:tcp://localhost/~/my_db
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=none
spring.flyway.user=sa
spring.flyway.password=
spring.flyway.schemas=PUBLIC

和我的应用程序-prod.properties:

spring.datasource.url=jdbc:mysql://localhost/my_db
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.username=user
spring.datasource.password=pass
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=none
spring.flyway.user=${spring.datasource.username}
spring.flyway.password=${spring.datasource.password}
spring.flyway.schemas=my_db

V1__desc.sqlsrc/main/resources/db/migration其中是flyway的默认目录。在使用 MySQL 运行我的程序时,我没有收到任何错误和异常,并且我看到了我的表和flyway_schema_history. 但是我在运行 spring boot 默认上下文加载测试时遇到了这个异常:

Caused by: 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: Validate failed: 
Detected failed migration to version 1 (my_db)

我什至将我的飞行路线位置更改为其他地方,但它没有改变。某人可以帮忙吗?

标签: javaspring-booth2flyway

解决方案


更改适用于我的项目的 fylway 版本...如果它不起作用,请发布更大的控制台日志


推荐阅读