簡體   English   中英

Flyway / Springboot 和 H2 內存數據庫的模式相關問題

[英]Schema related problems with Flyway / Springboot and H2 in-memory database

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO merchant_rating_detail (order_id, shop_id, user_id, rating, created_datetime, feedback_ids) VALUES(?, ?, ?, ?, ?, ?);]; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "merchant_rating_detail" not found (this database is empty); SQL statement: INSERT INTO merchant_rating_detail (order_id, shop_id, user_id, rating, created_datetime, feedback_ids) VALUES(?, ?, ?, ?, ?, ?); [42104-214] org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO merchant_rating_detail (order_id, shop_id, user_id, rating, created_datetime, feedback_ids) VALUES(?, ?, ?, ?, ?, ?);]; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "merchant_rating_detail" not found (this database is empty); SQL statement: INSERT INTO merchant_rating_detail (order_id, shop_id, user_id, rating, created_datetime, feedback_ids) VALUES(?, ?, ?, ?, ?, ?); [42104-214] `


# Flyway
spring.flyway.enabled= false

# H2
spring.datasource.url=jdbc:h2:mem:testdb;DATABASE_TO_UPPER=false;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.defer-datasource-initialization=true

`

我正在嘗試通過單元測試,但不知道如何去做。 我如何以正確的方式實施 Flyway。

我嘗試添加;DATABASE_TO_UPPER=false;DB_CLOSE_ON_EXIT=FALSE 和 spring.jpa.defer-datasource-initialization=true 但沒有用

Flyway 通過將 flyway 文件添加到資源文件夾中來工作。 首先(在資源中)添加一個名為 db 的文件夾,在 db 中添加一個名為 migration 的文件夾。 然后在遷移中添加一個名為 V00X__initial.sql 的文件。 將 X 替換為數字,例如 1。接下來是 2。然后將查詢寫入 .sql 文件。 Flyway 將在應用程序或測試啟動時運行這些查詢。

對於測試,您通常會創建一個 V001__make_tables.sql 文件,其中包含一個生成表的查詢。 然后一個V002__insert_data.sql文件插入數據,然后在測試中查看是否添加了所述數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM