首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Postgres数据库中插入行“错误:重复键值违反唯一约束”,尽管表中没有条目

无法在Postgres数据库中插入行“错误:重复键值违反唯一约束”,尽管表中没有条目
EN

Stack Overflow用户
提问于 2019-12-09 13:16:55
回答 1查看 742关注 0票数 0

我有一个带有模式的表:

代码语言:javascript
复制
    Table: "public.system_configuration_parameter"

        Column     |            Type             | Collation | Nullable |                     Default                      
    ---------------+-----------------------------+-----------+----------+--------------------------------------------------
     id            | integer                     |           | not null | nextval('system_configuration_id_seq'::regclass)
     name          | character varying           |           | not null | 
     type          | character varying           |           | not null | 
     value         | character varying           |           |          | 
     default_value | character varying           |           | not null | 
     date_added    | timestamp without time zone |           | not null | now()
     date_modified | timestamp without time zone |           | not null | now()

    Indexes:
        "system_configuration_parameter_pkey" PRIMARY KEY, btree (id)
        "system_configuration_parameter_name_key" UNIQUE CONSTRAINT, btree (name)

以下查询结果为错误:

代码语言:javascript
复制
insert into system_configuration_parameter (name, type, value ,default_value) values ('serverPerformanceMode','String','standardMode','standardMode');
ERROR:  duplicate key value violates unique constraint "system_configuration_parameter_name_key"
DETAIL:  Key (name)=(serverPerformanceMode) already exists.

问题是,在名称为“serverPerformanceMode”的表中不存在任何条目。

代码语言:javascript
复制
shubhdb=# select value from system_configuration_parameter where name = ('serverPerformanceMode');
(0 rows)

我正在使用postgres 9.3,我已经完成了postgres到升级版10的迁移,目前我的系统中已经安装了这两个版本。

我曾经使用相同的数据库,具有相同的结构,它以前运行得非常好。这甚至在postgres-10上都很好,只有当我使用postgres-9.3和相同的构建时才会出现问题。

有人知道这件事吗?还是面临着同样的问题?

感谢您的阅读。

EN

回答 1

Stack Overflow用户

发布于 2019-12-09 16:37:05

这种类型的问题通常是由用户错误引起的。您可能连接到一个数据库来执行插入,另一个连接到执行查询的不同数据库(或者可能是同一个数据库的不同模式)。您能使用相同的连接对象,而不是在不同的连接上手动运行查询,从而使插入跟踪错误的代码吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59249738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档