Integrity Constraint Violation

From NeoWiki

Revision as of 20:39, 24 August 2008 by Sardisson (Talk | contribs)
Jump to: navigation, search

Description

This error message appears in NeoBase.

The full text will be something like this:

Integrity constraint violation - no parent 4, table: Table A in statement [ALTER TABLE "Table A" ADD FOREIGN KEY ("field name A") REFERENCES "Table B" ("field name B")

Cause

It occurs when you are trying to relate Table A to Table B by means of the two fields named. The field from table A ("field name A") is called a Foreign Key (FK). Any field that links into another table (Table B, in this case) is called a Foreign Key. Remember that every table must have its own Primary Key (PK)

It means that there is data in field name A on one of the records in Table A that does not match any of the data in field name B on the records in Table B.

Solution

Check your data. Make certain that every record in table A has a value in field name A that can be matched to an instance of field name B.

An example:

Table A = Purchases field name A = customer number
Table B = Customers field name B = customer ID
customer number customer ID
0 3
1 4
2 5

The problem with the data frequently occurs when test data is entered by hand and it's hard to keep track of the automatically created Primary Keys.

Personal tools