Answers.Body: <p>Turned out to be a filter value in the report that was referencing a mailing group that no longer exists. It's 'id' was therefore missing from the civicrm_group table.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-14T11:12:30.437Z
Answers.LastActivityDate: 2020-02-14T11:12:30.437Z
Answers.UserDisplayName: Michael Chaplin
Answers.Body: <p>So I feel rather silly, all that was needed was to go into the report and edit the filters so that it was no longer looking at the group that no longer existed rather than going to the report via the shortcut we have which ran the report and hence brought up the error.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-14T11:13:01.880Z
Answers.LastActivityDate: 2020-02-14T11:13:01.880Z
Answers.UserDisplayName: Jade
Body: <p>CiviCRM version: 5.19.4</p>
  
  <p>CMS: Drupal 7.69</p>
  
  <p>PHP version: 7.1</p>
  
  <p>When trying to view the Mailing Details Report page, I get the following error: </p>
  
  <pre><code>DB Error: Constraint violation
  </code></pre>
  
  <p>Looking in the error logs, it is due to the group_id column as you can see here:</p>
  
  <pre><code>[nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`prefix`.`civicrm_group_contact`, CONSTRAINT `FK_civicrm_group_contact_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]"])
  </code></pre>
  
  <p>The important bit being: </p>
  
  <pre><code>CONSTRAINT `FK_civicrm_group_contact_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`)
  </code></pre>
  
  <p>I sort of understand why this error has come about, it's due to a <code>group_id</code> in the <code>civicrm_group_contact</code> table not being found in under the <code>group_id</code> column of the <code>civicrm_group</code> table (I think).</p>
  
  <p>I have tried running the following to try and find which row(s) is causing this problem: </p>
  
  <pre><code>SELECT * FROM `civicrm_group_contact` WHERE group_id NOT IN (SELECT id from civicrm_group)
  </code></pre>
  
  <p>However, this returned no results. </p>
  
  <p>I have also truncated the cache tables which is the solution to a few of the other problems I have found whilst researching and cleared normal CiviCRM cache.</p>
  
  <p>It's not just me getting this error, it's anyone else trying to access the same page getting the error as well.</p>
  
  <p>I've found a lot of similar questions regarding this but most of them have not have any solutions and the ones that do, I have either tried them or do not apply to me. </p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>EDIT: Added the backtrace from the ConfigAndLog file in the hope it helps solve my problem.</p>
  
  <pre><code>#6 /home/.../public_html/sites/all/modules/civicrm/packages/DB/mysqli.php(933): DB_common-&gt;raiseError(-3, NULL, NULL, "\nREPLACE INTO civicrm_group_contact ( group_id, contact_id, status )\nVALUES...", "1452 ** Cannot add or update a child row: a foreign key constraint fails (`cr...")
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-13T19:37:49.793Z
Comments.Text: To help you get help - what have you tried? - Also is it possible to include the full error message from your Civicrm ConfigAndLog log file - ideally it would be great to see the full sql statement that fails. (https://civicrm.org/extensions/civicrm-log-viewer - if you need help finding)
Comments.UserDisplayName: Luke Stewart
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-14T07:24:55.740Z
Comments.Text: I've tried what's already mentioned in my question, the error is from the ConfigAndLog file, I just excluded most of it and included the bit I thought was important, I'll edit my question to include a bit more of it though :)
Comments.UserDisplayName: Jade
Tags: <drupal><error><groups><sql>
Title: Constraint violation when viewing Mailing Detail Report (group_id the cause)
ThreadText: # Constraint violation when viewing Mailing Detail Report (group_id the cause)
  
  (Asked by: username_0 on 2020-02-13)
  
  CiviCRM version: 5.19.4
  
  CMS: Drupal 7.69
  
  PHP version: 7.1
  
  When trying to view the Mailing Details Report page, I get the following error:
  
  ```
  DB Error: Constraint violation
  
  ```
  
  Looking in the error logs, it is due to the group\_id column as you can see here:
  
  ```
  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`prefix`.`civicrm_group_contact`, CONSTRAINT `FK_civicrm_group_contact_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]"])
  
  ```
  
  The important bit being:
  
  ```
  CONSTRAINT `FK_civicrm_group_contact_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`)
  
  ```
  
  I sort of understand why this error has come about, it's due to a `group_id` in the `civicrm_group_contact` table not being found in under the `group_id` column of the `civicrm_group` table (I think).
  
  I have tried running the following to try and find which row(s) is causing this problem:
  
  ```
  SELECT * FROM `civicrm_group_contact` WHERE group_id NOT IN (SELECT id from civicrm_group)
  
  ```
  
  However, this returned no results.
  
  I have also truncated the cache tables which is the solution to a few of the other problems I have found whilst researching and cleared normal CiviCRM cache.
  
  It's not just me getting this error, it's anyone else trying to access the same page getting the error as well.
  
  I've found a lot of similar questions regarding this but most of them have not have any solutions and the ones that do, I have either tried them or do not apply to me.
  
  Any help would be greatly appreciated.
  
  EDIT: Added the backtrace from the ConfigAndLog file in the hope it helps solve my problem.
  
  ```
  #6 /home/.../public_html/sites/all/modules/civicrm/packages/DB/mysqli.php(933): DB_common->raiseError(-3, NULL, NULL, "\nREPLACE INTO civicrm_group_contact ( group_id, contact_id, status )\nVALUES...", "1452 ** Cannot add or update a child row: a foreign key constraint fails (`cr...")
  
  ```
  
  **Tags:** drupal, error, groups, sql
  
  > **Comments:**
  > **username_1**: To help you get help - what have you tried? - Also is it possible to include the full error message from your Civicrm ConfigAndLog log file - ideally it would be great to see the full sql statement that fails. (https://civicrm.org/extensions/civicrm-log-viewer - if you need help finding)  
  > **username_0**: I've tried what's already mentioned in my question, the error is from the ConfigAndLog file, I just excluded most of it and included the bit I thought was important, I'll edit my question to include a bit more of it though :)  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-02-14. Score: 1
  
  Turned out to be a filter value in the report that was referencing a mailing group that no longer exists. It's 'id' was therefore missing from the civicrm\_group table.
  
  
  ---
  
  ### Answer by username_0 on 2020-02-14. Score: 1
  
  So I feel rather silly, all that was needed was to go into the report and edit the filters so that it was no longer looking at the group that no longer existed rather than going to the report via the shortcut we have which ran the report and hence brought up the error.
  
  
  ---
  
  