2016-11-09 172 views
0

当我尝试删除从表1的纪录我收到此错误信息:为什么我得到SQL状态:23503上不存在的外键

ERROR: update or delete on "table1" violates foreign key constraint "<unnamed>" on "table2" 
DETAIL: Key (idtb1)=(1569) is still referenced from table "table2". 
********** Error ********** 

ERROR: update or delete on "table1" violates foreign key constraint "<unnamed>" on "table2" 
SQL state: 23503 
Detail: Key (idtb1)=(1569) is still referenced from table "table2". 

的问题是,我没有任何外键在table2上。

这里创建表

CREATE TABLE table1 
(
    idtb1 integer NOT NULL DEFAULT nextval('"table1_idtb1_seq"'::text), 
    nometb1 character varying(16), 
    stato character varying(4), 
    capit character(1), 
    email character varying(2000), 
    impianti boolean NOT NULL DEFAULT true 
) 
WITH OIDS; 
ALTER TABLE table1 
    OWNER TO postgres; 

    CREATE TABLE table2 
(
    idtb2 integer NOT NULL DEFAULT nextval('"table2_idtb2_seq"'::text), 
    idn integer DEFAULT 0, 
    dataarr date, 
    oraarr time without time zone, 
    arrinc character varying(1), 
    orind character varying(15), 
    pprovenienza character varying(30), 
    flgaggiunte character(1), 
    ocm text, 
    flageliminato character varying(1), 
    nomea character varying(50), 
    nomeb character varying(50), 
    pesc double precision 
) 
WITH OIDS; 
ALTER TABLE table2 
    OWNER TO postgres; 

脚本是一个古老的数据库

“在x86_64-未知Linux的GNU,由GCC海湾合作委员会(GCC)编译的PostgreSQL 4.4.7 8.0.26 20120313(Red Hat 4.4.7-4)“

我该如何继续?

+1

'WITH OIDS'已弃用,不应再使用。如果你删除它,这会改变吗?另外:你正在使用的**精确** Postgres版本是什么? 'select version()' –

+0

为什么你使用这样一个过时和不受支持的版本?您的示例适用于任何支持的Postgres版本。 –

+0

是的,是旧的过时和不受支持的版本,但现在无法更新。 –

回答

0

这看起来有点像数据损坏。

也许您应该安装PostgreSQL 9.6,pg_dumpall群集并将其加载到9.6数据库中。也许这会让问题消失。

相关问题