Java FlywayException:无法扫描位置中的 SQL 迁移:classpath:db/migration

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23501244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 23:25:55  来源:igfitidea点击:

FlywayException: Unable to scan for SQL migrations in location: classpath:db/migration

javadatabasemavenflyway

提问by Federico Piazza

I'm trying to start using flyway with maven integration but can't make it work.

我正在尝试开始使用带有 maven 集成的 flyway,但无法使其工作。

I'm following the documentation seems to be very simple so no strange things seem to be done.

我正在关注文档似乎很简单,所以似乎没有做过奇怪的事情。

My pom.xmlis the following:

我的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.test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>


  <build>
        <plugins>
            <!-- Flyway plugin configuration -->
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <url>jdbc:mysql://localhost:3306/test</url>
                    <user>test_fede</user>
                    <password>test_fede</password>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.21</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

  <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>13.0.1</version>
        </dependency>

        <!-- DB dependencies -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.21</version>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>compile</scope>
        </dependency>
  </dependencies>
</project>

I have the directory resources/db/migration/without any migration yet.

我有目录resources/db/migration/ 还没有任何迁移。

When I issuing flyway:info on cygwin or cmd I got an flyway error:

当我在 cygwin 或 cmd 上发出 flyway:info 时,我收到了一个 flyway 错误:

$ mvn compile flyway:info
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.test:test:jar:0.0.1-SNAPSHOT
[INFO]    task-segment: [compile, flyway:info]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [flyway:info {execution: default-cli}]
[INFO] Database: jdbc:mysql://localhost:3306/test (MySQL 5.5)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] org.flywaydb.core.api.FlywayException: Unable to scan for SQL migrations in location: classpath:db/migration

Embedded error: Unable to determine URL for classpath location: db/migration (ClassLoader: org.codehaus.classworlds.RealmClassLoader@5bcdbf6)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Tue May 06 11:06:15 CST 2014
[INFO] Final Memory: 17M/223M
[INFO] ------------------------------------------------------------------------

Can give me a hand on this?

可以帮我解决这个问题吗?

Thans a lot.

比很多。

采纳答案by Federico Piazza

Well, just for you to know.

嗯,只是为了让你知道。

I found the problem, it happens when we setup flyway in our environment but we don't have any migration to be executed.

我发现了这个问题,当我们在我们的环境中设置 flyway 时会发生这种情况,但我们没有任何要执行的迁移。

It shouldn't display a classpath error but fortunately it's working.

它不应该显示类路径错误,但幸运的是它正在工作。

By the way, another problem I found is that after executing initif we check with infonothing is displayed. And if we add a new migration with V1then infowon't show it unless we change it to V1_1

顺便说一下,我发现的另一个问题是,在执行init 后,如果我们检查信息,则不会显示任何内容。如果我们使用V1添加一个新的迁移,那么除非我们将其更改为V1_1,否则信息不会显示它

Hope to help

希望有所帮助

回答by yankee

This also happens if the compile goal is not executed before calling flyway:migrate. Actually this IS included in the quick start manual. It says:

如果在调用 flyway:migrate 之前未执行编译目标,也会发生这种情况。实际上,这是包含在快速入门手册中的。它说:

mvn compileflyway:migrate

mvn编译飞行路线:迁移

However if you miss that detail and start to just call mvn flyway:migrate, the SQL file will not get copied into the target directory (actually the target directory will not even exist) and you get this cryptic error.

但是,如果您错过了那个细节并开始只调用mvn flyway:migrate,SQL 文件将不会被复制到目标目录中(实际上目标目录甚至不存在),并且您会收到这个神秘的错误。

回答by Lakshmi

I ran into the same problem. In my case, I had my migration script in the wrong directory that had caused the issue. I moved the script V1__Create_person_table.sql to the right directory at resources/db/migration/ and it worked!!

我遇到了同样的问题。就我而言,我的迁移脚本位于导致问题的错误目录中。我将脚本 V1__Create_person_table.sql 移动到 resources/db/migration/ 中的正确目录,并且它起作用了!!

回答by adithya

I faced the same issue. But when i obeserved the logs keenly i found flywaydb is looking in db/migration folder for the script but my script is in db/migrate. so, after correcting the path from db/migrate to db/migration it works!!.

我遇到了同样的问题。但是当我敏锐地观察日志时,我发现 flywaydb 正在 db/migration 文件夹中查找脚本,但我的脚本在 db/migrate 中。因此,在更正从 db/migrate 到 db/migration 的路径后,它可以工作了!!。

回答by prograhammer

Here's a dumb mistake I've made where I got this pesky error:

这是我在遇到这个讨厌的错误时犯的一个愚蠢的错误:

Make sure you set your packaging as jarnot pomin your pom.xml. Then mvn installand make sure you have a jar for that project in your M2 folder otherwise you will get this error since the migration file wasn't copied over and found.

请确保你设定的包装如jar没有pom在你的pom.xml。然后mvn install确保您的 M2 文件夹中有该项目的 jar,否则您将收到此错误,因为未复制和找到迁移文件。

回答by Merveille van Eck

I had a similar problem too. in my case i thought i had named the directories correctly after triple checking everything. Turned out that i typed migrationsinstead of migration. As soon as i fixed this everything was fine.

我也有类似的问题。就我而言,我认为在三重检查所有内容后我已经正确命名了目录。结果是我输入的migrations不是migration. 一旦我解决了这个问题,一切都很好。

Just before this i had another issue with the underscore after the version marker (V1) in the migration filename. It needs to be a dunder (double underscore) so its always V1__description.sql.

就在此之前,我在迁移文件名中的版本标记 (V1) 之后遇到了另一个下划线问题。它需要是一个 dunder(双下划线)所以它总是V1__description.sql.

Seems like none of the flyway issues i encounter are big mess-up's. it's always something small that can be easily fixed. It's just about finding out what the problem is. That's the hard part.

似乎我遇到的飞行路线问题都不是大问题。它总是很容易修复的小东西。这只是为了找出问题所在。这是最难的部分。

回答by Thami Bouchnafa

I had a similar problem and it was because when I created the migration directory I gave it the name db.migrationdirectly.

我有一个类似的问题,这是因为当我创建迁移目录时,我db.migration直接给了它名称。

By creating the directory dband then inside it the migrationdirectory it worked.

通过创建目录db,然后在其中创建migration它工作的目录。