【问题标题】:Flyway Exception for invalid characters in the version版本中无效字符的 Flyway 异常
【发布时间】:2018-11-01 21:31:14
【问题描述】:

我正在尝试将 Flyway 与我的简单 maven 项目集成以用于学习目的。

我正在使用以下插件和配置:

            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>4.0.3</version>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.9</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <url>jdbc:mysql://${database.host}:${database.port}/${database.schema}?useUnicode=true&amp;characterEncoding=UTF-8&amp;characterSetResults=UTF-8</url>
                    <user>${database.user}</user>
                    <password>${database.password}</password>
                    <sqlMigrationPrefix>V_</sqlMigrationPrefix>
                    <sqlMigrationSeparator>__</sqlMigrationSeparator>
                    <locations>
                        <location>filesystem:src/main/resources/db/migrations</location>
                    </locations>
                </configuration>
            </plugin>

这是我的示例迁移 sql 的名称:

V_1__create_new_table.sql

我不确定我做错了什么,但我不断收到以下异常:

org.flywaydb.core.api.FlywayException: Invalid version containing non-numeric characters. Only 0..9 and . are allowed. Invalid version: V.1

我确实参考了以下问题,正如您在配置中看到的那样,我已经完成了所要求的操作: Similar Question

【问题讨论】:

    标签: maven flyway


    【解决方案1】:

    您可以简单地尝试仅将 V 定义为您的迁移前缀,并将您的迁移文件命名为 V1__Create_New_Table.sql(这些是 Flyway 的默认设置)。

    您将V_ 定义为前缀和V_1__Create_New_Table.sql 作为文件名的方式是导致问题的原因,因为这告诉Flyway 此迁移的版本为V.1,这当然是不正确的。

    对于较少数量的版本,您可以选择这样的方法:V1_1__Create_New_Table.sql 例如,这将为您提供1.1 的迁移版本。

    在您提供的相关 SO 答案中,建议的答案是使用 V_ 作为前缀和 _ 作为分隔符,而您已在插件配置中定义 __ 作为插件分隔符。

    【讨论】:

    • @NLabrahmi 我现在看到了这个问题。非常感谢。
    猜你喜欢
    • 2013-02-23
    • 2013-05-04
    • 2010-10-25
    • 2011-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    相关资源
    最近更新 更多