【问题标题】:Flyway migration failed using H2使用 H2 的 Flyway 迁移失败
【发布时间】:2020-05-24 23:21:26
【问题描述】:

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

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

【问题讨论】:

  • "检测到迁移到版本 1 失败" => 之前迁移失败!
  • 同意上面的评论——Vfiles 是校验和的,这是在修改迁移文件时给出的错误。我通常使用内存版本,但我设置 MYSQL 模式有点不同,可能会有所帮助 - spring.datasource.url=jdbc:h2:mem:my_db;MODE=MYSQL

标签: java spring-boot h2 flyway


【解决方案1】:

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

【讨论】:

  • 你改成哪个版本了?
  • 从5.0.1到5.0.0的插件版本示例
【解决方案2】:

我会说:

将 flyway 设置为调试模式。 检查sql脚本的内容。

最好的。

【讨论】:

  • 这是一条评论。没有答案!
  • 我应该在哪里将flyway设置为调试模式?我设置了spring.flyway.stream=true,但在运行/调试时没有看到任何 sql 语句正在执行。
猜你喜欢
  • 2020-02-25
  • 2019-01-16
  • 2012-07-21
  • 2012-08-09
  • 2014-08-02
  • 2017-12-11
  • 2017-09-25
  • 2023-03-05
  • 2019-04-28
相关资源
最近更新 更多