【问题标题】:Flyway migration in postgresql?postgresql中的Flyway迁移?
【发布时间】:2022-01-10 21:14:41
【问题描述】:

我正在尝试使用这样的请求向 Postgresql 添加一个条目

insert into customer (id, email, name, number_telephone) VALUES (public.hibernate_sequence_customer.nextval, 'abc@jar.ru' , 'Henry', '89132547898');

,但是flyway会报错

Error: table "hibernate_sequence_customer" is missing in the FROM clause

在项目结构中 enter image description here

【问题讨论】:

标签: postgresql spring-boot flyway


【解决方案1】:

序列的下一个值是accessed 通过nextval('public.hibernate_sequence_customer'),而不是点符号。

insert into customer (
    id,
    email,
    name,
    number_telephone)
VALUES (
    nextval('public.hibernate_sequence_customer'),
    'abc@jar.ru' ,
    'Henry',
    '89132547898');

但如果将id 列定义为serial,则根本不需要调用序列。

create table customer (
    id serial primary key,
    email text,
    name text,
    number_telephone text);

只需在您的insert 中跳过它:

insert into customer (
    email,
    name,
    number_telephone)
VALUES (
    'abc@jar.ru' ,
    'Henry',
    '89132547898');

如果您稍后需要参考负责id 列的序列 - 例如,获取其当前值 - 您可以使用currval(pg_get_serial_sequence('customer','id'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-16
    • 2021-08-29
    • 2015-01-15
    • 2019-12-27
    • 2016-04-08
    • 2013-03-03
    • 2021-06-07
    • 2019-01-16
    相关资源
    最近更新 更多