Re: help with referential integrity

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Soma Interesting <dfunct(at)telus(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: help with referential integrity
Date: 2000-12-12 18:06:06
Message-ID: Pine.BSF.4.21.0012121005110.31856-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 11 Dec 2000, Soma Interesting wrote:

>
> I'm attempting, for the first time, to make use of referential integrity,
> but I'm getting an error.
>
> Warning: PostgreSQL query failed: ERROR: referential integrity violation -
> key referenced from LessonsPages not found in Lessons
>
> Here is the table's structures:
>
> CREATE SEQUENCE "LessonsPages_id_seq";
> CREATE TABLE "LessonsPages" (
> "id" int4 DEFAULT nextval('"LessonsPages_id_seq"') NOT NULL,
> "lid" int4 NOT NULL
> REFERENCES "Pages"
> ON DELETE CASCADE,
> "pid" int4 NOT NULL
> REFERENCES "Lessons"
> ON DELETE CASCADE,
> PRIMARY KEY ("lid", "pid")
> );

Did you really want lid referencing pages and
pid referencing lessons rather than the other
way around? It seems below you're inserting
things the other way around.

> The error comes when:
>
> INSERT INTO "Pages" (order_num) VALUES (1);
> SELECT id FROM "Pages";
> | id |
> 16
> 1 Row
>
> INSERT INTO "Lessons" (lesson_name, order_num) VALUES ('test lesson', 2);
> SELECT id FROM "Lessons";
> | id |
> 9
> 1 Row
>
> INSERT INTO "LessonsPages" (lid,pid) VALUES (9,16);
>
>
> What am I doing wrong?
>
> - - - - - - -
> - - - - -
> WARNING: Some experts believe that use of any keyboard may cause serious
> injury.
> Consult Users Guide.
> dfunct(at)telus(dot)net
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2000-12-12 18:09:36 Re: Postgres failover implementation
Previous Message Tom Lane 2000-12-12 18:00:23 Re: conversion