0

When merging 2 contacts this error appears however when the contact is checked the merge has succeeded:

$Fatal Error Details = array:3 [
  "message" => "DB Error: constraint violation"
  "code" => null
  "exception" => CRM_Core_Exception {#1782
    #message: "DB Error: constraint violation"
    #code: -3
    #file: "/var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/api/api.php"
    #line: 138
    #cause: null
    -_trace: null
    -errorData: array:8 [
      "error_code" => -3
      "sql" => "INSERT INTO `civicrm_activity` (`activity_type_id` , `subject` , `activity_date_time` , `status_id` , `priority_id` , `parent_id` ) VALUES ( 54 , 'Contact ID 11170 has been merged into Contact ID 41737 and deleted.' ,  20231214131919 ,  2 ,  2 ,  202919 ) "
      "debug_info" => "INSERT INTO `civicrm_activity` (`activity_type_id` , `subject` , `activity_date_time` , `status_id` , `priority_id` , `parent_id` ) VALUES ( 54 , 'Contact ID 11170 has been merged into Contact ID 41737 and deleted.' ,  20231214131919 ,  2 ,  2 ,  202919 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`xxx.xxx`.`civicrm_activity`, CONSTRAINT `civicrm_activity_ibfk_3` FOREIGN KEY (`parent_id`) REFERENCES `civicrm_activity_fudge` (`id`) ON DELETE SET NULL)]"
      "entity" => "Activity"
      "action" => "create"
      "is_error" => 1
      "error_message" => "DB Error: constraint violation"
      "debug_information" => "INSERT INTO `civicrm_activity` (`activity_type_id` , `subject` , `activity_date_time` , `status_id` , `priority_id` , `parent_id` ) VALUES ( 54 , 'Contact ID 11170 has been merged into Contact ID 41737 and deleted.' ,  20231214131919 ,  2 ,  2 ,  202919 ) "
    ]
    trace: {
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/api/api.php:138 {
        civicrm_api3(string $entity, string $action, array $params = [])
        › if (is_array($result) && !empty($result['is_error'])) {
        ›   throw new CRM_Core_Exception($result['error_message'], $result['error_code'] ?? 'undefined', $result);
        › }
      }
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/CRM/Dedupe/Merger.php:2188 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/CRM/Dedupe/Merger.php:2104 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/CRM/Contact/Form/Merge.php:324 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/CRM/Core/Form.php:622 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/CRM/Core/StateMachine.php:144 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/CRM/Core/QuickForm/Action/Next.php:43 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/packages/HTML/QuickForm/Controller.php:203 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/packages/HTML/QuickForm/Page.php:103 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/CRM/Core/Controller.php:355 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/CRM/Utils/Wrapper.php:98 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/CRM/Core/Invoke.php:295 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/CRM/Core/Invoke.php:69 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm/CRM/Core/Invoke.php:36 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm.php:121 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/components/com_civicrm/civicrm.php:40 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/libraries/src/Dispatcher/LegacyComponentDispatcher.php:71 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/libraries/src/Dispatcher/LegacyComponentDispatcher.php:73 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/libraries/src/Component/ComponentHelper.php:361 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/libraries/src/Application/AdministratorApplication.php:143 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/libraries/src/Application/AdministratorApplication.php:186 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/libraries/src/Application/CMSApplication.php:293 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/includes/app.php:61 { …}
      /var/www/vhosts/xxx.xxx/httpdocs/administrator/index.php:32 { …}

Running CiviCRM 5.68 , PHP 8.1 , Joomla 4.4.1

2 Answers 2

0

According to this:

Cannot add or update a child row: a foreign key constraint fails
(`xxx.xxx`.`civicrm_activity`, CONSTRAINT `civicrm_activity_ibfk_3` 
FOREIGN KEY (`parent_id`) REFERENCES `civicrm_activity_fudge` 
(`id`) ON DELETE SET NULL)]

you may want to check the civicrm_activity table structure, discover where the civicrm_activity_fudge has come from and edit or remove this reference.

0

Run below query

ALTER TABLE civicrm_activity_contact DROP FOREIGN KEY civicrm_activity_ibfk_3;

ALTER TABLE civicrm_activity_contact 
ADD CONSTRAINT `FK_civicrm_activity_contact_activity_id` FOREIGN KEY (`activity_id`) REFERENCES `civicrm_activity` (`id`) ON DELETE CASCADE;

Note: Take db backup before running query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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