Thread: referential integrity violation

referential integrity violation

From
tony
Date:
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

Help =:-D

Cheers

Tony Grant



Re: referential integrity violation

From
Stephan Szabo
Date:
It means that the particular key value that is used in the referencing
table does not have an associated value in the referenced table,
not the columns themselves.

On 30 Jul 2001, tony wrote:

> 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
>


Re: referential integrity violation

From
missive@frontiernet.net (Lee Harr)
Date:
On Mon, 30 Jul 2001 15:19:27 +0000 (UTC), tony <tony@animaproductions.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.