Answers.Body: <p>It seems you have some entries remaining in <code>civicrm_group_contact</code> which point to the deleted <code>civicrm_group</code> entry?</p>
  
  <p>You can confirm this with a query to look for group contact entries which point to a missing group.</p>
  
  <pre><code>-- 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);
  </code></pre>
  
  <p>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 ...).</p>
  
  <pre><code>-- 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);
  </code></pre>
  
  <p>If updating, you'll want to avoid creating duplicate entries by reassigning group_id without checking for existing group additions.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-26T16:18:14.760Z
Answers.Text: 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.
Answers.UserDisplayName: Nina Gonzalez
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-29T21:37:17.837Z
Answers.Text: 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.
Answers.UserDisplayName: Nina Gonzalez
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-24T21:07:07.233Z
Answers.LastActivityDate: 2016-08-24T21:16:07.577Z
Answers.LastEditDate: 2016-08-24T21:16:07.577Z
Answers.UserDisplayName: Chris Burgess
Body: <p>I am unable to make certain edits to CiviCRM; unable to edit certain records and unable to edit the visibility of groups. </p>
  
  <p>I think the problem is this:
  Cannot add or update a child row: a foreign key constraint fails (`ea...")</p>
  
  <p>The error message is referring to a group '58' which I deleted and replaced with group "62".</p>
  
  <p>How do I find the exact problem and fix it?</p>
  
  <p>I'm on WP 4.5.3 with CiviCRM 4.7.9.</p>
  
  <p>Here is the error message:</p>
  
  <blockquote>
    <p>Database Error Code: Cannot add or update a child row: a foreign key
    constraint fails (<code>xxx_civicrm</code>.<code>civicrm_group_contact</code>,
    CONSTRAINT <code>FK_civicrm_group_contact_group_id</code> FOREIGN KEY
    (<code>group_id</code>) REFERENCES <code>civicrm_group</code> (<code>id</code>) ON DELETE CASCADE),
    1452 </p>
  </blockquote>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T16:27:53.390Z
Comments.Text: Did you do any editing directly in the database or did you do everything through the UI? (e.g. deleting group 58)
Comments.UserDisplayName: Laryn
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T17:29:17.510Z
Comments.Text: 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.
Comments.UserDisplayName: Nina Gonzalez
Tags: <database><error><groups><smartgroups>
Title: Unable to Import, edit certain records and edit Group settings: DB Error: constraint violation
ThreadText: # Unable to Import, edit certain records and edit Group settings: DB Error: constraint violation
  
  (Asked by: username_0 on 2016-08-19)
  
  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
  
  **Tags:** database, error, groups, smartgroups
  
  > **Comments:**
  > **username_1**: Did you do any editing directly in the database or did you do everything through the UI? (e.g. deleting group 58)  
  > **username_0**: 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-08-24. Score: 1
  
  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.
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_0**: 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.  
  
  ---
  
  