postgresql duplicate key violates unique constraint
2016-04-08 19:31
721 查看
> 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!
相关文章推荐
- PostgreSQL新手入门教程
- PostgreSQL教程(十):性能提升技巧
- PostgreSQL教程(二):模式Schema详解
- PostgreSQL教程(十三):数据库管理详解
- 深入解读PostgreSQL中的序列及其相关函数的用法
- PostgreSQL教程(八):索引详解
- PostgreSQL教程(三):表的继承和分区表详解
- 简单介绍Ruby on Rails对PostgreSQL数组类型的支持
- PostgreSQL教程(十九):SQL语言函数
- PostgreSQL教程(四):数据类型详解
- PostgreSql新手必学入门命令小结
- 用一整天的时间安装postgreSQL NTFS权限
- FREEBSD安装POSTGRESQL笔记
- PostgreSQL8.3.3安装方法第1/2页
- 深入理解PostgreSQL的MVCC并发处理方式
- PostgreSQL教程(一):数据表详解
- PostgreSQL教程(十二):角色和权限管理介绍
- PostgreSQL教程(五):函数和操作符详解(1)
- 15个postgresql数据库实用命令分享