Advertisement

【异常】Flyway failed to initialize: none of the following migration scripts locations could be found

阅读量:

一、报错内容

复制代码
    ***************************
    APPLICATION FAILED TO START
    ***************************
    
    Description:
    
    Flyway failed to initialize: none of the following migration scripts locations could be found:
    
    	- classpath:db/migration
    
    
    Action:
    
    Review the locations above or check your Flyway configuration
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    

为什么它不起作用?

二、异常说明

Flyway无法初始化:没有找到以下迁移脚本位置
说明,SpringBoot无法识别resources文件下的db/migration的内容。
在这里插入图片描述
这样就无法读取到我编写的SQL脚本

三、问题解决

3.1 解决方案1:调整目录

后经一番探索,发现是idea一个路径创建bug导致,idea多级目录折叠显示时如下图:
在这里插入图片描述
改为多级目录即可,如下tree中展示的。
在这里插入图片描述
在这里插入图片描述

3.2 解决方案2:不校验

随着Flyway的位置支持已经发展到支持通配符、云存储等,正如本期所述,Spring Boot’s准确检查位置的能力已经下降。因此,在Spring Boot2.5中,对位置检查的支持被弃用,在弃用期过后,它将被完全删除。同时,您可以通过将spring.flyway.check-location设置为false来关闭它。
在这里插入图片描述

复制代码
      flyway:
    ## 是否启用flyway
    enabled: true
    ## 编码格式,默认UTF-8
    encoding: UTF-8
    ## 迁移sql脚本文件存放路径,默认db/migration
    locations: classpath:db/migration
    check-location: false
    ## 迁移sql脚本文件名称的前缀,默认V
    sql-migration-prefix: V
    ## 迁移sql脚本文件名称的分隔符,默认2个下划线__
    sql-migration-separator: __
    ## 迁移sql脚本文件名称的后缀
    sql-migration-suffixes: .sql
    ## 迁移时是否进行校验,默认true
    validate-on-migrate: true
    ## 当迁移发现数据库非空且存在没有元数据的表时,自动执行基准迁移,新建schema_version表
    baseline-on-migrate: true
    
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    

https://docs.spring.io/spring-boot/docs/2.4.x/reference/htmlsingle/#spring.flyway.check-location

全部评论 (0)

还没有任何评论哟~