Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 2D4F19F9C04 for ; Mon, 24 Sep 2007 09:26:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 51759-04 for ; Mon, 24 Sep 2007 09:26:31 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from trabant.cianoz.org (host31-194-149-62.serverdedicati.aruba.it [62.149.194.31]) by postgresql.org (Postfix) with ESMTP id 24A1D9F9C13 for ; Mon, 24 Sep 2007 09:26:38 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by trabant.cianoz.org (Postfix) with ESMTP id BD229384229 for ; Mon, 24 Sep 2007 14:26:30 +0200 (CEST) X-Virus-Scanned: by amavisd-new at actionlinesrl.it Received: from trabant.cianoz.org ([127.0.0.1]) by localhost (mail.actionlinesrl.it [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vfy6VAqtt8w0 for ; Mon, 24 Sep 2007 14:26:20 +0200 (CEST) Received: from [141.250.41.212] (unknown [141.250.41.212]) by trabant.cianoz.org (Postfix) with ESMTP id 9CE503841BC for ; Mon, 24 Sep 2007 14:26:20 +0200 (CEST) Subject: foreign key problem From: ivan marchesini Reply-To: marchesini@unipg.it To: pgsql-sql@postgresql.org Content-Type: text/plain Organization: University of Perugia Date: Mon, 24 Sep 2007 14:34:46 +0200 Message-Id: <1190637286.4804.72.camel@ivangeo> Mime-Version: 1.0 X-Mailer: Evolution 2.10.3 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/150 X-Sequence-Number: 29363 Dear users, I'm trying to create constraints into a db they give me from access... I'm using pgadmin to create a new foreign key for the relationship between two table.. I have a table called "generalita" wich contains a column called "cod_carg": ___________________ select cod_carg from generalita group by cod_carg; cod_carg ---------- 2 0 1 (4 righe) ___________________ I have another table, called "diz_carg" that contain, into a column called "cod_carg" (that is a primary key), the domain values for the "cod_carg" column of "generalita": __________________ select cod_carg from diz_carg group by cod_carg; cod_carg ---------- 1 0 2 (3 righe) __________________ so when I try to create the foreign key I obtain: ALTER TABLE generalita ADD CONSTRAINT fkey_diz_cod_carg FOREIGN KEY (cod_carg) REFERENCES diz_carg (cod_carg) ON UPDATE NO ACTION ON DELETE NO ACTION; ____________________________ ERROR: insert or update on table "generalita" violates foreign key constraint "fkey_diz_cod_carg" DETAIL: Key (cod_carg)=( ) is not present in table "diz_carg". ____________________________ can I allow null values for "generalita.cod_carg" although it is a foreign key for "diz_carg.cod_carg"? I apologize if it is a stupid question.... :-( many thanks to all -- Ti prego di cercare di non inviarmi files .doc, .xls, .ppt, .dwg. Preferisco formati liberi. Please try to avoid to send me .doc, .xls, .ppt, .dwg files. I prefer free formats. http://it.wikipedia.org/wiki/Formato_aperto http://en.wikipedia.org/wiki/Open_format Ivan Marchesini Department of Civil and Environmental Engineering University of Perugia Via G. Duranti 93/a 06125 Perugia (Italy) e-mail: marchesini@unipg.it ivan.marchesini@gmail.com tel: +39(0)755853760 fax (university): +39(0)755853756 fax (home): +39(0)5782830887 jabber: geoivan73@jabber.org