(psycopg2.IntegrityError) duplicate key value violates unique constraint

插入数据时遇到上述标题错误,发现是nextval error.

# 查看表最大id
SELECT MAX(id) FROM area;
-----------------------------------------------
 max 
-----
 630
(1 row)
------------------------------------------------

# 查看该表nextval
SELECT nextval('area_id_seq');
------------------------------------------------
 max 
-----
 630
(1 row)
------------------------------------------------

# 执行修改序列
SELECT setval('area_id_seq', (SELECT MAX(id) FROM area)+1);
------------------------------------------------
 setval 
--------
    631
(1 row)

------------------------------------------------

你可能感兴趣的:((psycopg2.IntegrityError) duplicate key value violates unique constraint)