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...")