【发布时间】:2018-10-20 03:47:43
【问题描述】:
我有一个现有的数据库。我创建了两个迁移
$ ls src/main/resources/db/migration/
V1__create_stats.sql V2__create_sources.sql
我在application.properties中设置了以下内容
# Prevent complaints when starting migrations with existing tables.
flyway.baselineOnMigrate = true
否则会报错org.flywaydb.core.api.FlywayException: Found non-empty schemagalaxybadgewithout metadata table! Use baseline() or set baselineOnMigrate to true to initialize the metadata table.
当我尝试启动应用程序时,它会跳过迁移并且不执行它们!我在 MySQL 中使用 show tables;,发现它们不存在!
>mvn spring-boot:run
...
2018-05-09 18:43:03.671 INFO 24520 --- [ restartedMain] o.f.core.internal.util.VersionPrinter : Flyway 3.2.1 by Boxfuse
2018-05-09 18:43:04.420 INFO 24520 --- [ restartedMain] o.f.c.i.dbsupport.DbSupportFactory : Database: jdbc:mysql://localhost:3306/galaxybadge (MySQL 5.5)
2018-05-09 18:43:04.486 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbValidate : Validated 0 migrations (execution time 00:00.030s)
2018-05-09 18:43:04.704 INFO 24520 --- [ restartedMain] o.f.c.i.metadatatable.MetaDataTableImpl : Creating Metadata table: `galaxybadge`.`schema_version`
2018-05-09 18:43:05.116 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbBaseline : Schema baselined with version: 1
2018-05-09 18:43:05.145 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbMigrate : Current version of schema `galaxybadge`: 1
2018-05-09 18:43:05.146 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbMigrate : Schema `galaxybadge` is up to date. No migration necessary.
我查看了this answer,但没有帮助,而且似乎给出了错误的属性名称。这是它创建的schema_version 表。
> select * from schema_version;
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
| version_rank | installed_rank | version | description | type | script | checksum | installed_by | installed_on | execution_time | success |
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
| 1 | 1 | 1 | << Flyway Baseline >> | BASELINE | << Flyway Baseline >> | NULL | root | 2018-05-09 18:43:05 | 0 | 1 |
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
Spring Boot 1.5.6、FlyWay Core 3.2.1
【问题讨论】:
-
你如何在
Application根类中调用 flyway? -
我不必从我的应用程序中调用 FlyWay。 Spring 会自动执行此操作。 docs.spring.io/spring-boot/docs/current/reference/html/…
-
您是否尝试过将迁移脚本放在:
db/migration/mysql下?
标签: java spring-boot flyway