postgresql duplicate key violates unique constraint

前端之家收集整理的这篇文章主要介绍了postgresql duplicate key violates unique constraint前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
> 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!
原文链接:https://www.f2er.com/postgresql/194596.html

猜你在找的Postgre SQL相关文章