当前位置:网站首页>Flyway error source code analysis - Validate failed: Migrations have failed validation
Flyway error source code analysis - Validate failed: Migrations have failed validation
2022-08-06 17:27:00 【Integer_Double】
一、异常信息
Started the project this morning,Suddenly the following exception occurred,Baidu did not find a suitable solution,Decided to start with the source code,看看能不能解决.
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.exception.FlywayValidateException: Validate failed: Migrations have failed validation
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:917) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:582) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) ~[spring-boot-2.4.3.jar:2.4.3]
at com.zhx.realpro.CloudAlarmApplication.main(CloudAlarmApplication.java:33) ~[classes/:na]
Caused by: org.flywaydb.core.api.exception.FlywayValidateException: Validate failed: Migrations have failed validation
at org.flywaydb.core.Flyway$1.execute(Flyway.java:172) ~[flyway-core-7.1.1.jar:na]
at org.flywaydb.core.Flyway$1.execute(Flyway.java:164) ~[flyway-core-7.1.1.jar:na]
at org.flywaydb.core.Flyway.execute(Flyway.java:538) ~[flyway-core-7.1.1.jar:na]
at org.flywaydb.core.Flyway.migrate(Flyway.java:164) ~[flyway-core-7.1.1.jar:na]
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66) ~[spring-boot-autoconfigure-2.4.3.jar:2.4.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782) ~[spring-beans-5.3.4.jar:5.3.4]
... 19 common frames omitted
二、异常分析
根据错误信息,报的是FlywayValidateException异常,Find this class and hit a breakpoint
启动项目,查看调用链
Found where the exception was thrown,Put a breakpoint on the line before it to start the project,Because the result is judged before throwing an exceptionValidateResult validateResult = doValidate(database, migrationResolver, schemaHistory, schemas, callbackExecutor, true);
Follow up on this line
ValidateResult validateResult = new DbValidate(database, schemaHistory, schemas, migrationResolver, configuration, ignorePending, callbackExecutor).validate();

validate方法里面,在Callable的call方法做校验,This piece feels a bit over-engineered,Did not find the benefit of starting a new thread.
migrationInfoService的refresh方法sql文件加载进来了,Don't watch this.Then go downList<ValidateOutput> invalidMigrations = migrationInfoService.validate();
验证所有sql文件的checksum,如果sqlThe file is executed for the first time,会产生一个checksum.之后改了sql文件的内容checksum的值就会发生改变,从而验证失败validateError就不会为空,那么invalidMigrationswill add one.进入migrationInfo.validate();
Went to this block and found twochecksum不一致.跟进去resolvedMigration.checksumMatches
不一致就返回false
返回一个ErrorDetails,错误信息很详细,But in the end there is no output,看看怎么回事,返回到DbValidate.DbValidate方法,callreturned after executionresult.
目前为止resultThere are still detailed error messages
校验失败的sqlEnter if the file is not empty validationError = new ErrorDetails(ErrorCode.VALIDATE_ERROR, "Migrations have failed validation");,The exception information here is hard-coded“Migrations have failed validation”,More detailed error messages are not output,Remember the old versionflyway是有输出的.This change is not intuitive.返回到Flyway.migrate
校验失败,抛出异常信息“ Migrations have failed validation”.
三、解决方案
As mentioned earlier, it is generally due tosqlThe file was changed after the first execution.
- 方案一:不要改动sql文件,增加新的sqlfile to modify the table
- 方案二:directly to the database tableflyway_schema_history中的checksumChange to a new onechecksum,But it is not recommended to change the library directly.估计也是这个原因,新版的flywayDo not put new oneschecksum打印出来了
边栏推荐
- win7和win10哪个占用资源少 win7和win10占用资源详解
- What does the 0x0000001a blue screen code mean? How to solve the 0x0000001a blue screen code
- 【kali-漏洞利用】(3.4)Metasploit渗透攻击应用:MySQL渗透过程
- windows7激活产品密钥最新免费2022大全(含旗舰版、专业版、家庭版、通用版)
- 系统提示无法保存打印机设置0x000006d9怎么解决(win7win10通用)
- 王学岗————从零实现手写音视频通话(H265)
- 2021最新Office激活密钥正版分享
- 对于目标文件系统文件过大放不到u盘里怎么办 u盘空间够为何提示文件过大
- win7怎么打开无线投屏功能 win7投屏到电视机
- cdr是什么软件 cdr格式用什么软件打开
猜你喜欢

win7旗舰版强行删除开机密码 win7开机密码忘了怎么解除

excel提示无法打开文件,因为文件格式或文件扩展名无效怎么解决

bluetooth外围设备找不到驱动程序怎么办 bluetooth外围设备没有驱动程序

王学岗————从零实现手写音视频通话(H265)

win7开机0x0000007b修复不了 win7蓝屏0x0000007b怎么修复

为什么企业不愿意升级ERP系统

office2019永久密钥激活码最新_office2019激活密钥码终身激活(100%激活)

win7开机0x0000007b修复不了 win7开机蓝屏0x0000007b

C专家编程 第7章 对内存的思考 7.7 总线错误

百度搜索排名:三板斧,有哪些?
随机推荐
`英语` 2022/8/3
【ROS2原理2】必须要ROS2系统的四个要求
colorama\ansitowin32.py 错误 line 59, in closed return stream.closed 解决方案
C专家编程 第7章 对内存的思考 7.5 数据段和堆
bluetooth外围设备找不到驱动程序怎么办 bluetooth外围设备没有驱动程序
备忘一下配置@Cacheable的失效时间(Redis指定某些Cache Key的失效时间)
win7缺失dll文件一键修复 msvcr120.dll丢失怎样修复win7
8.paddlepaddle之loss损失函数自定义
01 【TypeScript简介 初体验】
`数学` 微积分基本定理
2g内存可以装64位win7吗 win7内存支持多大
excel提示无法打开文件,因为文件格式或文件扩展名无效怎么解决
CMake教程Step7(安装打包)
win7开机0x0000007b修复不了 win7开机蓝屏0x0000007b
Integer缓存策略
测试同学参与开发的代码走读,做code review有必要么?
FP6601AP5 CPC-16L Type-A HVDCP控制器与插入/输出自动检测
面试20场,我总结了面试问题及解答!激光+IMU融合定位方向
如何用WebGPU流畅渲染千万级2D物体:基于光追管线
win7运行速度提高90% 怎么提高win7系统运行速度