【问题标题】:Flyway did not create tablesFlyway 没有创建表格
【发布时间】:2021-05-23 02:10:45
【问题描述】:

我一直在尝试使用 spring boot 和 flyway 创建一个 Web 应用程序。构建工具是 Gradle。但是,当我尝试运行程序时,Flyway 只创建了一个名为 flyway_schema_hystory 的表,但没有从 SQL 脚本创建表。脚本V1__Create_all_tables.sql 位于正确的包src/main/resources/db/migration 上。在build.gradle 中添加了依赖关系,在app.properties 中也添加了flyway 属性。 Spring boot 运行无误。

build.gradle 依赖项

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

    compileOnly 'org.projectlombok:lombok:1.18.16'
    annotationProcessor 'org.projectlombok:lombok:1.18.16'

    compile group: 'org.springframework.boot', name: 'spring-boot', version: '2.4.2'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.4.2'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.4.2'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.4.2'

    annotationProcessor('org.hibernate:hibernate-jpamodelgen:6.0.0.Alpha5')

    compile group: 'org.postgresql', name: 'postgresql', version: '42.2.18'

    compile group: 'org.flywaydb', name: 'flyway-core', version: '7.5.3'
}

app.properties

#Databse
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/db_mydatabase
spring.datasource.username=postgres
spring.datasource.password=***
spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=none

#Flyway
spring.flyway.baselineOnMigrate=true
spring.flyway.check-location=true
spring.flyway.locations=classpath:db/migration
spring.flyway.schemas=public
spring.flyway.enabled=true

创建表的sql脚本示例(我使用的是postgresql):

create table my_table (
                       id serial not null constraint cover_pkey primary key,
                       name varchar(30) not null ,
                       is_deleted boolean not null
);

flyway_schema_hystory

可能有什么问题?

【问题讨论】:

  • 我使用相同的配置(postgres、gradle、springboot、flyway)并且有一个类似的属性文件。不同之处之一是我的baselineOnMigration 是这样写的baseline-on-migrate。你可以尝试改变吗? @OlSi
  • 不幸的是没有为我工作。不过还是谢谢@dextertron_
  • 尝试更改名称,也许 v1 是为 flyway 初始迁移保留的。尝试类似 V1_1__Create_all_tables.sql
  • 这是我对 db 的全部配置(这里的文本格式不好)-> spring: jpa: show-sql: true database: postgresql generate-ddl: false hibernate: ddl-auto: validate use -new-id-generator-mappings: false 数据源: 平台: postgres url: jdbc:postgresql://localhost:5432/dev_db 用户名: dev_user 密码: dev_pass flyway: enabled: true 位置: classpath:db/migrations baseline-on-迁移:真
  • 另外,您能否确认您可以在项目的外部库中看到 flyway 库?

标签: java spring-boot flyway


【解决方案1】:

尝试更改名称,我认为 v1 是为 flyway 的初始迁移保留的。尝试类似 V1_1__create_all_tables.sql

【讨论】:

    猜你喜欢
    • 2020-02-15
    • 2013-05-29
    • 2019-11-06
    • 2020-07-20
    • 2019-03-03
    • 2013-07-06
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多