1

I am unable to make certain edits to CiviCRM; unable to edit certain records and unable to edit the visibility of groups.

I think the problem is this: Cannot add or update a child row: a foreign key constraint fails (`ea...")

The error message is referring to a group '58' which I deleted and replaced with group "62".

How do I find the exact problem and fix it?

I'm on WP 4.5.3 with CiviCRM 4.7.9.

Here is the error message:

Database Error Code: Cannot add or update a child row: a foreign key constraint fails (xxx_civicrm.civicrm_group_contact, CONSTRAINT FK_civicrm_group_contact_group_id FOREIGN KEY (group_id) REFERENCES civicrm_group (id) ON DELETE CASCADE), 1452

  • Did you do any editing directly in the database or did you do everything through the UI? (e.g. deleting group 58) – Laryn - CEDC.org Aug 22 '16 at 16:27
  • I deleted the group from the UI and had the problem. When I tried to fix the problem, I went into the database and deleted the hidden groups. I also noticed that I had a profile for that group, so I deleted that and cleared cache in CiviCRM, but that did not solve it. I checked the database and the group is not listed. – Nina Gonzalez Aug 22 '16 at 17:29
1
+50

It seems you have some entries remaining in civicrm_group_contact which point to the deleted civicrm_group entry?

You can confirm this with a query to look for group contact entries which point to a missing group.

-- Show contacts who belong to a group that doesn't exist.
SELECT * 
  FROM civicrm_group_contact 
 WHERE group_id NOT IN (SELECT id FROM civicrm_group);

If entries are found with that query, you can clear them out (or update them to point to the new group, or export those contact IDs, or ...).

-- Standard disclaimers apply; back up your DB before doing this!
DELETE  
  FROM civicrm_group_contact 
 WHERE group_id NOT IN (SELECT id FROM civicrm_group);

If updating, you'll want to avoid creating duplicate entries by reassigning group_id without checking for existing group additions.

  • The problem started when I had three groups suddenly attached as children to another group. This new parent group is displayed on a public web page, Hence the reason I deleted that group and created a new group. Now I see any time I delete a group in CiviCRM it causes this DB error. Plus every time I open Manage Group another group is added to this parent group. I did not create any parent groups, it is happening on its one. And it seems CiviCRM will not allow me to remove a parent group. Parent group is required once you have a parent group. – Nina Gonzalez Aug 26 '16 at 16:18
  • I used your query and there was no record of Group 58. I decided to roll the database back one week. It did not completely solve the problem, but the database is functioning. – Nina Gonzalez Aug 29 '16 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.