【问题标题】:Flyway migration error after flyway:baselineflyway 后的 Flyway 迁移错误:基线
【发布时间】:2021-02-07 23:00:22
【问题描述】:

我在我的宠物项目中使用了 Java+Spring+Maven+Flyway+Postgres。 这里 db/migration 中有两个 sql 文件。 当我第一次运行应用程序时

mvn spring-boot:run

或在应用程序开始使用之前

mvn flyway:migrate -Dflyway.url=jdbc:postgresql://localhost:5432/university -Dflyway.user=tester -Dflyway.password=test

Db 是正确创建的,没有任何错误,但是当我想首先创建 V1 时

 mvn flyway:baseline -Dflyway.url=jdbc:postgresql://localhost:5432/university -Dflyway.user=tester -Dflyway.password=test

然后:

mvn flyway:migrate -Dflyway.url=jdbc:postgresql://localhost:5432/university -Dflyway.user=tester -Dflyway.password=test

我发现错误:

[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:6.4.4:migrate (default-cli) on project universityschedule: org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException: 
[ERROR] Migration V2__add_email_and_phone_to_person.sql failed
[ERROR] ------------------------------------------------------
[ERROR] SQL State  : 42P01
[ERROR] Error Code : 0
[ERROR] Message    : ERROR: relation "public.teacher" does not exist

为什么会这样?如何解决?

【问题讨论】:

    标签: postgresql maven flyway


    【解决方案1】:

    Flyway 基线将用于非空数据库。在这种情况下,假设第一次迁移代表将数据库创建到其当前状态所需的 sql。因此,它假设您的V1 迁移不打算执行,只是将其标记为baseline

    如果您只是迁移,跳过基线步骤,它应该可以正常工作。

    【讨论】:

      猜你喜欢
      • 2021-11-22
      • 2019-08-07
      • 2019-01-16
      • 2013-03-03
      • 2014-06-03
      • 2011-11-05
      • 2019-12-27
      • 2018-05-10
      • 2020-05-29
      相关资源
      最近更新 更多