【问题标题】:Flyway not finding my sql migrations in db/migrationFlyway 在 db/migration 中找不到我的 sql 迁移
【发布时间】:2013-04-07 20:56:38
【问题描述】:

错误: [错误] com.googlecode.flyway.core.api.FlywayException:无法确定类路径位置的 URL:db/migration (ClassLoader: ClassRealm [plugin>com.googlecode.flyway:flyway-maven-plugin:2.1.1, parent : sun.misc.Launcher$AppClassLoader@43be2d65])

我遵循了快速入门,所以我还没有真正做任何复杂的事情。

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.cpt.migrations</groupId>
  <artifactId>cpt_migrations</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>cpt_migrations</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.24</version>
    </dependency>
  </dependencies>
  <build>
      <plugins>
          <plugin>
              <groupId>com.googlecode.flyway</groupId>
              <artifactId>flyway-maven-plugin</artifactId>
              <version>2.1.1</version>
              <configuration>
                  <user>root</user>
                  <password></password>
                  <driver>com.mysql.jdbc.Driver</driver>
                  <url>jdbc:mysql://localhost:3306/cpt</url>
              </configuration>
          </plugin>
      </plugins>
  </build>
</project>

而我的文件夹结构是规定的PROJECT_ROOT/src/main/resources/db/migration/V1__Base_version.sql:

当我从 PROJECT_ROOT 执行时,我收到错误: mvn flyway:迁移

【问题讨论】:

    标签: flyway


    【解决方案1】:

    别忘了先调用compile,确保资源被复制过来。

    【讨论】:

    • 什么意思?你能解释得更好吗?我用的是 netbeans 7.4
    • @Axel Fontaine like Jeff 我已经配置了我的 pom.xml,并且我的 .sql 脚本位于资源下的 db/migration 文件夹中。在执行编译 flyway:migrate 我得到 com.googlecode .flyway.core.api.FlywayException:无法创建架构``:数据库名称不正确''可能是什么问题?我的 sql 文件名为 test.sql
    • 如果我的 sql 文件在当前文件夹中而不是在 db/migration 中怎么办?如何解决问题?我也编译然后调用 migrate。
    【解决方案2】:

    必须编译:

    mvn compile flyway:migrate
    

    你可以使用

    <executions>
              <execution>
                <id>compile</id>
                <phase>compile</phase>
                <goals>
                  <goal>migrate</goal>
                </goals>
              </execution>
              <execution>
                <id>clean</id>
                <phase>clean</phase>
                <goals>
                  <goal>clean</goal>
                </goals>
              </execution>
            </executions>
    

    <plugin>..</plugin> 
    

    然后只需要 mvn compile 来执行迁移任务

    【讨论】:

    • 我不认为在编译时执行迁移是个好主意。
    【解决方案3】:

    从目标目录所在目录执行 mvn 命令。

    【讨论】:

      【解决方案4】:

      就我而言,我必须明确设置

      flyway.locations=classpath:db/migration
      

      在我的 application.properties (Spring Boot) 中让它工作。

      【讨论】:

      • 设置在哪里?不要以为每个人都是这些方面的专家!
      • @Willa 在 Spring Boot 的 application.properties 文件中。我更新答案
      【解决方案5】:

      在我的情况下,这个错误是因为创建了名称为 db.migration 的包 而不是db -> migration

      【讨论】:

        猜你喜欢
        • 2019-09-10
        • 1970-01-01
        • 1970-01-01
        • 2019-05-02
        • 2012-02-07
        • 2012-06-28
        • 2012-04-07
        • 2014-05-14
        • 2018-04-15
        相关资源
        最近更新 更多