From: | Raymond O'Donnell <rod(at)iol(dot)ie> |
---|---|
To: | erobles <erobles(at)sensacd(dot)com(dot)mx> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: NOTICE: ignoring incomplete trigger group for constraint |
Date: | 2010-05-22 16:17:39 |
Message-ID: | 4BF803A3.4020909@iol.ie |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 22/05/2010 17:03, erobles wrote:
> ERROR: there is no unique constraint matching given keys for referenced
> table "table_name'"
>
>
> there is a way to solve this?? what can i do ??
It means you need to have a primary key, or at least a unique
constraint, on the target table which uses the column(s) which the
foreign key references.
For example:
postgres=# create table a(f1 integer, f2 integer);
CREATE TABLE
postgres=# create table b(f3 integer, f4 integer);
CREATE TABLE
postgres=# alter table a add foreign key (f2) references b(f3);
ERROR: there is no unique constraint matching given keys for referenced
table "b"
If I now add a primary key to table b, it works:
postgres=# alter table b add primary key(f3);
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index
"b_pkey" for table "b"
ALTER TABLE
postgres=# alter table a add foreign key (f2) references b(f3);
ALTER TABLE
HTH.
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie
From | Date | Subject | |
---|---|---|---|
Next Message | Merlin Moncure | 2010-05-22 17:05:38 | Re: Alter column position |
Previous Message | erobles | 2010-05-22 16:03:33 | Re: NOTICE: ignoring incomplete trigger group for constraint |