gpt4 book ai didi

java - Liquibase 似乎对数据库运行变更集两次(或者 H2 数据库没有被清理)

转载 作者:行者123 更新时间:2023-11-29 04:16:55 24 4
gpt4 key购买 nike

所以我正在尝试在我的 jhipster 应用程序中运行集成测试,该应用程序目前(默认情况下,没有对测试配置进行任何更改)使用 H2 数据库。我运行了 mvnw clean test 并收到以下错误:

2018-08-09 16:05:56.340  INFO 276 --- [           main] .f.t.r.CustomAuditEventRepositoryIntTest : No active profile set, falling back to default profiles: default
2018-08-09 16:06:06.159 INFO 276 --- [ main] c.f.t.config.MetricsConfiguration : Initializing Metrics Log reporting
2018-08-09 16:06:16.258 ERROR 276 --- [ main] liquibase : classpath:config/liquibase/master.xml: config/liquibase/changelog/20180725185152_added_entity_Driver.xml::20180725185152-1::jhipster: Change Set config/liquibase/changelog/20180725185152_added_entity_Driver.xml::20180725185152-1::jhipster failed. **Error: Table "DRIVER" already exists**; SQL statement:
CREATE TABLE PUBLIC.driver (id BIGINT NOT NULL, first_name VARCHAR(255), middle_name VARCHAR(255), last_name VARCHAR(255), birth_date date, gender VARCHAR(255), suffix VARCHAR(255), weight FLOAT4, height VARCHAR(255), eye_color VARCHAR(255), hair_color VARCHAR(255), is_organ_donor BOOLEAN, drivers_license_id BIGINT, address_id BIGINT, CONSTRAINT PK_DRIVER PRIMARY KEY (id), UNIQUE (drivers_license_id)) [42101-197] [Failed SQL: CREATE TABLE PUBLIC.driver (id BIGINT NOT NULL, first_name VARCHAR(255), middle_name VARCHAR(255), last_name VARCHAR(255), birth_date date, gender VARCHAR(255), suffix VARCHAR(255), weight FLOAT4, height VARCHAR(255), eye_color VARCHAR(255), hair_color VARCHAR(255), is_organ_donor BOOLEAN, drivers_license_id BIGINT, address_id BIGINT, CONSTRAINT PK_DRIVER PRIMARY KEY (id), UNIQUE (drivers_license_id))]

所以“Driver table already exists”的错误让我想到了

答:Liquibase 在不需要时针对数据库运行变更集,或者可能运行了两次?

B:在 liquibase 运行之前,H2 数据库实际上并没有被清理 变更集。

有什么想法吗?

更新:测试目录的application.yml文件中hibernate和liquibase相关的属性如下:

datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:h2:mem:TouchQuote2Backend;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
name:
username:
password:
jpa:
database-platform: io.github.jhipster.domain.util.FixedH2Dialect
database: H2
open-in-view: false
show-sql: false
hibernate:
ddl-auto: none
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
properties:
hibernate.id.new_generator_mappings: true
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.hbm2ddl.auto: validate
liquibase:
contexts: test

我尝试更改 hibernate ddl-auto 属性以进行验证,但它仍然抛出相同的错误。

最佳答案

由于默认为 create-drop,很可能您让 Hibernate 生成了模式。根据 Spring Boot docs, Appendix A :

spring.jpa.hibernate.ddl-auto= # DDL mode. This is actually a shortcut for the "hibernate.hbm2ddl.auto" property. Defaults to "create-drop" when using an embedded database and no schema manager was detected. Otherwise, defaults to "none".

设置 spring.jpa.hibernate.ddl-auto=validate 以仅验证使用 Liquibase 创建的模式。

关于java - Liquibase 似乎对数据库运行变更集两次(或者 H2 数据库没有被清理),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51775187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com