使用Flyway向H2数据库Timestamp列插入指定格式日期报错求助
解决方案
1. 修复application.properties中的无效配置
你的配置里spring.datasource=capitole是错误的,会导致数据源配置异常,替换为:
spring.datasource.name=capitole
2. 修正日期解析的格式符与函数使用
H2数据库中,parsedatetime函数的hh代表12小时制,而你的时间是24小时制(00、23),会导致解析失败。将格式串中的hh替换为HH:
insert into PRICES(brand_id, start_date, end_date, price_list, product_id,priority,price,curr) values (1, PARSEDATETIME('2020-06-14-00.00.00','yyyy-MM-dd-HH.mm.ss'), PARSEDATETIME('2020-12-31-23.59.59','yyyy-MM-dd-HH.mm.ss'), 1, 35455, 0, 35.50, 'EUR');
3. 更稳妥的日期插入方式(推荐)
直接使用H2支持的TIMESTAMP字面量,避免函数解析的潜在问题:
insert into PRICES(brand_id, start_date, end_date, price_list, product_id,priority,price,curr) values (1, CAST('2020-06-14 00:00:00' AS TIMESTAMP), CAST('2020-12-31 23:59:59' AS TIMESTAMP), 1, 35455, 0, 35.50, 'EUR');
4. 确保Schema一致性
建表时明确指定schema,避免Flyway与数据源的schema不匹配:
drop table if exists capitole.PRICES; create table capitole.PRICES ( Id int not null AUTO_INCREMENT, brand_id int not null, start_date TIMESTAMP not null, end_date TIMESTAMP not null, price_list int not null, product_id int not null, priority int not null, price double not null, curr varchar(50) not null );
内容的提问来源于stack exchange,提问作者Margarita
相关产品推荐
相关产品推荐

