Ask Your Question
0

Can not create relation in Base

asked 2017-08-31 13:08:28 +0100

Denko gravatar image

Trying to create a new relation in Base between two tables I get following error. Have no idea what this means. Please help:

SQL Status: 23000 Error code: -177

Integrity constraint violation - no parent 2, table: RelationsTable2 in statement [ALTER TABLE "RelationsTable2" ADD FOREIGN KEY ("CID") REFERENCES "CenterData" ("ID")]

edit retag flag offensive close merge delete

Comments

The error code presented refers to inserting NULL's into a field. Are you getting this error on the creation of the relation or when trying to enter data? Was there data in the tables before attempting this? Posting the table structures and exactly what you are linking would be of help.

Ratslinger gravatar imageRatslinger ( 2017-08-31 19:52:14 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2017-09-01 12:14:02 +0100

peterwt gravatar image

I assume you are trying to create a one to many relationship between CenterData, the one side, and RelationsTable2, the many side, and ID in CenterData is the unique Primary Key. Do you have data in these tables when you try to create the link? If so the error suggests that you have orphaned records in RelationsTable2. Have you deleted some records in CenterData so some values of ID no longer exist but records containing this value for CID are still in the RelationsTable2? The error you get suggests this is the case - there are records in RelationsTable2 with no parent, i.e. with no ID value for the records that have this CID value. If this is the case you need to delete the records in RelationsTable2 that contain the CID values that no longer exist in CenterData.

edit flag offensive delete link more

Comments

Thank you so much for clarifying this. There are indeed orphant records (the only thing not thought of yet). I will locate these, 'clean up' and see what happens.

Denko gravatar imageDenko ( 2017-09-02 10:06:19 +0100 )edit

@Denko did deleting orphaned records solve the problem?

peterwt gravatar imagepeterwt ( 2017-09-27 16:36:54 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-08-31 13:08:28 +0100

Seen: 466 times

Last updated: Sep 01 '17