它意味着不便插入一排,而无需使用序列或更新id来值2
例如:
t=# create table so47(id serial primary key,v text);
CREATE TABLE
t=# insert into so47(v) select 'some';
INSERT 0 1
t=# insert into so47(id,v) select 2, 'more';
INSERT 0 1
t=# insert into so47(v) select 'some more';
ERROR: duplicate key value violates unique constraint "so47_pkey"
DETAIL: Key (id)=(2) already exists.
回答在评论的问题是: Postgres使用序列为autoincrement列获取下一个值。要检查下一个值,运行(在我的例子情况下):
t=# select * from so47_id_seq ;
sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called
---------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
so47_id_seq | 2 | 1 | 1 | 9223372036854775807 | 1 | 1 | 31 | f | t
(1 row)
重置NEXTVAL,你必须:
t=# alter sequence so47_id_seq restart with 3;
ALTER SEQUENCE
t=# insert into so47(v) select 'some more';
INSERT 0 1
然后,它会从不存在的价值恢复序列。
在你的情况,你需要:
select max(id)+1 from "user"
得到的值,然后:
alter sequence user_id_seq restart with SELECTED_VALUE;
这意味着不便插入行,而无需使用序列或更新的ID,以值2 –
雅正确..它如何采取2也让我感到困惑? – lalithkumar
我已经在localhost做了应用程序,并把它推入heroku ..之后,只有它的显示错误.. – lalithkumar