我试图在Spring Boot项目中使用Hibernate和Spring JPA集成Flyway进行迁移.我得到以下例外:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Found non-empty schema "PUBLIC" without metadata table! Use init() or set initOnMigrate to true to initialize the metadata table.
Run Code Online (Sandbox Code Playgroud)
我pom.xml看起来像这样:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>3.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我正在使用Hibernate和一个用于postgres(开发阶段)和h2(本地)的配置java文件.签名看起来像这样:
@Bean(initMethod = "migrate")
public Flyway flyway() {
Flyway fly = new Flyway();
fly.clean();
fly.init();
//flyway.setInitOnMigrate(true);
fly.setSchemas("SBA_DIALOG");
//flyway.setLocations("filesystem:src/main/resources/db/migration");
fly.setDataSource(this.dataSource());
fly.migrate();
return fly;
}
@Bean(name = "sbaEntityManagerFactory") @DependsOn("flyway")
public …Run Code Online (Sandbox Code Playgroud)