X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A1E40D1B18F for ; Tue, 8 Jun 2004 20:18:11 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42242-08 for ; Tue, 8 Jun 2004 23:18:10 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 12E79D1B1D2 for ; Tue, 8 Jun 2004 20:18:05 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 9478A35652; Tue, 8 Jun 2004 16:18:07 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 92D4B3563C; Tue, 8 Jun 2004 16:18:07 -0700 (PDT) Date: Tue, 8 Jun 2004 16:18:07 -0700 (PDT) From: Stephan Szabo To: Michelle Murrain Cc: pgsql-sql@postgresql.org Subject: Re: simple addition of constraints problem In-Reply-To: Message-ID: <20040608161622.S64030@megazone.bigpanda.com> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/63 X-Sequence-Number: 18008 On Tue, 8 Jun 2004, Michelle Murrain wrote: > I'm trying to do something which seems really simple to me. (Postgres 7.3.4) > > I've got this table: > > charter_dev2=# \d rcourseinfo > Table "public.rcourseinfo" > Column | Type | Modifiers > -------------+-----------------------+--------------------------------------------------- > courseid | integer | not null default > nextval('rcourseinfo_seq'::text) > coursename | character varying(50) | > dept | character varying(30) | > number | character varying(4) | > section | character varying(2) | > trimester | character varying(5) | > schoolyear | character varying(8) | > facultyid | integer | > description | text | > credits | real | > Indexes: rcourseinfo_pkey primary key btree (courseid), > rcourseinfo_number_index btree (number) > > With a primary key called 'courseid'. > > I've got a second table: > > charter_dev2=# \d coursesevaluations > Table "public.coursesevaluations" > Column | Type | Modifiers > -----------------------+---------+---------------------------------------------------------- > courseid | integer | > evalid | integer | > coursesevaluations_id | integer | not null default > nextval('coursesevaluations_seq'::text) > Indexes: coursesevaluations_pkey primary key btree (coursesevaluations_id), > coursesevaluations_evalid_index btree (evalid) > > > I'd like to make 'courseid' in this second table a foreign key, > referencing 'courseid' in the first table. So I did this command: > > charter_dev2=# ALTER TABLE coursesevaluations ADD CONSTRAINT rc_ce > FOREIGN KEY (courseid) REFERENCES rcourseinfo (courseid); > > And I get this result: > > NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s) > ERROR: rc_ce referential integrity violation - key referenced from > coursesevaluations not found in rcourseinfo > > This doesn't make any sense to me - the fields are named the same, > and are the same data type. I've pored over the docs, to no avail. > I'm sure I'm missing something really elementary, but it's escaping > me. That's the message for the constraint violation. It looks like perhaps the data doesn't meet the constraint (in 7.4 it would have shown you values, for 7.3 you'll have to look yourself).