Re: referential integrity violation

From: missive(at)frontiernet(dot)net (Lee Harr)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: referential integrity violation
Date: 2001-07-30 22:25:11
Message-ID: 9k4ms7$3r3u$1@node21.cwnet.roc.gblx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 30 Jul 2001 15:19:27 +0000 (UTC), tony <tony(at)animaproductions(dot)com>:
> Hello,
>
> While copying from a text file of tab delimited data I am getting
> " ERROR: <unnamed> referential integrity violation - key referenced
> from films not found in sales"
>
> The salesid field
> salesid INTEGER PRIMARY KEY DEFAULT NEXTVAL('sales_serial')
>
> exists

It sounds like the table is using a foreign key.

This is a way of linking two tables so that data that one table needs
will always be available in another table.

For instance, you might have a table library with columns
library_id and library_name

Then in another table book, you could tell which library owns the book
by having a column library_id which references table library. By making
the reference a foreign key constraint, you would never end up with a
library_id in the book table which did not have an entry in the library
table.

This would look like:

CREATE TABLE library (library_id integer PRIMARY KEY, library_name text);
CREATE TABLE book (book_name text, library_id integer REFERENCES library);

The answer to your question is one of two things:

1) make sure you are copying the data in the right order.
ie, copy in the table that holds the primary key that the
other tables are referencing first.

OR

2) drop the foreign key constraint until all of your data is loaded.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lee Harr 2001-07-30 22:33:42 Re: database information
Previous Message Hiroshi Inoue 2001-07-30 21:49:10 RE: Re: "Oracle's ROWNUM"