foreign Key problem

From: "Dave Page" <dpage(at)vale-housing(dot)co(dot)uk>
To: <pgsql-general(at)postgresql(dot)org>
Subject: foreign Key problem
Date: 2002-06-20 11:07:05
Message-ID: D85C66DA59BA044EB96AB9683819CF61015101@dogbert.vale-housing.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I have the following tables in a 7.2 database:

-- Table: sys_users
CREATE TABLE sys_users (
sys_guid int4 DEFAULT nextval('"sys_users_sys_guid_seq"'::text) NOT
NULL,
sys_email varchar(64),
sys_name varchar(64) NOT NULL,
sys_superuser bool DEFAULT 'f'::bool,
sys_active bool DEFAULT 't'::bool,
sys_tokens text,
sys_password varchar(128),
sys_comments text,
CONSTRAINT sys_users_pkey PRIMARY KEY (sys_guid)
) WITH OIDS;

-- Table: dms_categories
CREATE TABLE dms_categories (
dms_guid int4 DEFAULT nextval('"dms_categories_dms_guid_seq"'::text)
NOT NULL,
dms_created timestamptz,
dms_name varchar(64) NOT NULL,
dms_description text,
dms_parent_category int4,
dms_owner varchar(64) NOT NULL,
dms_deleted bool DEFAULT 'f'::bool,
CONSTRAINT dms_categories_pkey PRIMARY KEY (dms_guid)
) WITH OIDS;

-- Table: dms_acl
CREATE TABLE dms_acl (
dms_guid int4 DEFAULT nextval('"dms_acl_dms_guid_seq"'::text) NOT
NULL,
dms_category int4 NOT NULL,
dms_user int4 NOT NULL,
dms_read bool DEFAULT 't'::bool,
dms_write bool DEFAULT 'f'::bool,
CONSTRAINT dms_acl_pkey PRIMARY KEY (dms_guid),
CONSTRAINT dms_acl_dms_categories FOREIGN KEY (dms_category)
REFERENCES dms_categories (dms_guid) ON DELETE CASCADE ON UPDATE CASCADE
NOT DEFERRABLE INITIALLY IMMEDIATE,
CONSTRAINT dms_acl_sys_users FOREIGN KEY (dms_user) REFERENCES
sys_users (sys_guid) ON DELETE CASCADE ON UPDATE CASCADE NOT DEFERRABLE
INITIALLY IMMEDIATE
) WITH OIDS;

If I try to insert a record in dms_acl:

INSERT INTO dms_acl (dms_category, dms_user, dms_read, dms_write) VALUES
(102, 51, 'Y', 'Y')

I get the error:

ERROR: dms_acl_sys_users referential integrity violation - key
referenced from dms_acl not found in sys_users

A select on sys_users confirms that I do have a record with sys_guid =
51. I have also tried this with other known values from
sys_users.sys_guid & always get the error.

Any ideas gratefully received!

Regards, Dave.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2002-06-20 11:09:57 Re: how to evaluate a function only once for a query?
Previous Message Gianfranco Masia - Eprom s.r.l. 2002-06-20 11:03:15 Is it possible compile Pg 7.1.3 to run under Win98?