java - 使用 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.sql
在src/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)
我什至将我的飞行路线位置更改为其他地方,但它没有改变。某人可以帮忙吗?
解决方案
更改适用于我的项目的 fylway 版本...如果它不起作用,请发布更大的控制台日志
推荐阅读
- r - R Shiny 仅观察到特定的 reactiveVal 变化
- scikit-learn - ValueError:matmul:输入操作数 1 在其核心维度 0 中不匹配
- r - R:在for循环中使用索引
- javascript - 为什么我的引导 Javascript 不起作用(wordpress)
- php - PHP NumberFormatter parseCurrency 返回 false
- pandas - 具有相同行名的数据进入列
- flutter - 如何在颤动中制作具有圆边的按钮?
- winforms - 使用 WinForms 应用程序的 OAuth/OIDC SSO 的最佳实践?
- php - 不同目录中类文件的php错误日志
- terraform - 无法让 global_parameter 与 Terraform azurerm_data_factory 一起使用