java - 使用 H2 的 Flyway 迁移失败

标签 java spring-boot h2 flyway

我的 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

我在src/main/resources/db/migration中有V1__desc.sql,这是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)

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

最佳答案

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

关于java - 使用 H2 的 Flyway 迁移失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60136878/

相关文章:

java - 如何在 Android 中使用 Java 从服务数据中提取的字符串中删除双引号?

java - 使用 BFG Repo Cleaner 删除嵌套文件夹

java - OpenApi-Generator-Plugin - 创建 Webclient 时是否可以在 ApiClient 中生成 spring @Component 注解?

mysql - 如何将 mySql 数据库导出到嵌入式数据库(例如 H2)?

database - 将 Squeryl 和 H2 数据库用于桌面应用程序的性能问题

java - 二叉节点树,错误的父子

java - RenderScript 支持库中缺少 Mesh 类

Spring JPA 存储库查找所有不存在的内容

java - 从 json 响应中解析一个值,其中大部分负载都是冗余的

mysql - 为什么通过 H2 进行 spring-boot 测试,但它会将数据写入我本地的 mysql 数据库?