SpringBoot 整合Flyway 常见问题科普解决
Posted Adorable_Rocy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot 整合Flyway 常见问题科普解决相关的知识,希望对你有一定的参考价值。
很多网上关于Flyway整合springboot的说明并不明确
Flyway在6.0之前是有兼容的,在6.0之后是没有做兼容的,小编的版本是6.0+
报错如下:
Caused by: org.flywaydb.core.api.FlywayException: Validate failed: Detected failed migration to version 2.3.0.2020081801 (role rights)
at org.flywaydb.core.Flyway.doValidate(Flyway.java:1482)
at org.flywaydb.core.Flyway.access$100(Flyway.java:85)
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1364)
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1356)
at org.flywaydb.core.Flyway.execute(Flyway.java:1711)
at org.flywaydb.core.Flyway.migrate(Flyway.java:1356)
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1830)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1767)
...
- 原因一:版本过高,表名变成了flyway_schema_history
解决:
flyway:
baseline-on-migrate: true
encoding: utf-8 #字符编码
out-of-order: true #是否允许无序的迁移
enabled: true #是否启用flyway
table: schema_version
validate-on-migrate: true
官方建议是配置table:schema_version
- 原因二:
sql语句执行错误,其实就是你的脚本有问题,找到schema_version 删除出错的脚本的记录,然后修改脚本再重新执行即可
以上是关于SpringBoot 整合Flyway 常见问题科普解决的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot 的 DataJpaTest 与 Flyway