加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql duplicate key violates unique constraint

发布时间:2020-12-13 17:07:37 所属栏目:百科 来源:网络整理
导读:Throws an exception due to the following SQL error: duplicate key violates unique constraint. Your primary key index isn't in sync or something.Can you login to psql and run the following?SELECT MAX(id) FROM entities;What is the result?The
> Throws an exception due to the following SQL error: duplicate key
> violates unique constraint.

Your primary key index isn't in sync or something.

Can you login to psql and run the following?

SELECT MAX(id) FROM entities;

What is the result?

Then run...

SELECT nextval('entities_id_seq');

This should be higher than the last result.

Is it  the same or lower? If so... did you do some importing or
restoring? (your sequence might be off)

If it's not higher... run this to try and fix it. (run a quick
pg_dump first...)

SELECT setval('entities_id_seq',(SELECT MAX(id) FROM entities)+1);

reload your app...and see if its still happening.

Good luck!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读