使用H2的空中通道迁移失败

问题描述 投票:1回答:2

我的Spring Boot应用程序使用H2进行测试,我还添加了flyway maven插件和依赖项(flyway-core和flyway-spring-test)。这是我的application-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

和我的application-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.sql中有src/main/resources/db/migration,这是飞行路线的默认目录。使用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)

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

java spring-boot h2 flyway
2个回答
0
投票

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


-1
投票

我会说:

将飞行通道设置为调试模式。检查sql脚本的内容。

最佳

© www.soinside.com 2019 - 2024. All rights reserved.