Answers.Body: <p>Looks like a data integrity issue. civicrm_relationship_cache table has CiviCase data which is deleted, Will need to clear those first by running below query and re-run the upgrade.</p>
  <pre><code>DELETE crc.* FROM civicrm_relationship_cache crc
  LEFT JOIN civicrm_case cc
    ON crc.case_id = cc.id 
  WHERE cc.id IS NULL AND crc.case_id IS NOT NULL
  </code></pre>
  <p>HTH</p>
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-11T00:56:58.850Z
Answers.Text: Absolutely genius!!!!
Answers.UserDisplayName: FullStack-Dev
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-11T00:41:28.363Z
Answers.LastActivityDate: 2021-12-11T00:41:28.363Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>Drupal 7
  CiviCRM upgrade from 5.38.0 to 5.44.0</p>
  <p>DB Error:</p>
  <pre><code>ALTER TABLE `civicrm_relationship_cache` ADD CONSTRAINT `FK_civicrm_relationship_cache_case_id` FOREIGN KEY (`case_id`) REFERENCES `civicrm_case` (`id`) ON DELETE CASCADE; [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`drupal7_crm`.`#sql-5c_2ad8`, CONSTRAINT `FK_civicrm_relationship_cache_case_id` FOREIGN KEY (`case_id`) REFERENCES `civicrm_case` (`id`) ON DELETE CASCADE)]
  </code></pre>
  
Tags: <upgrade>
Title: Upgrading CiviCRM from 5.38 to 5.44 causes DB Error: constraint violation Error
ThreadText: # Upgrading CiviCRM from 5.38 to 5.44 causes DB Error: constraint violation Error
  
  (Asked by: username_0 on 2021-12-11)
  
  Drupal 7
  CiviCRM upgrade from 5.38.0 to 5.44.0
  
  DB Error:
  
  ```
  ALTER TABLE `civicrm_relationship_cache` ADD CONSTRAINT `FK_civicrm_relationship_cache_case_id` FOREIGN KEY (`case_id`) REFERENCES `civicrm_case` (`id`) ON DELETE CASCADE; [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`drupal7_crm`.`#sql-5c_2ad8`, CONSTRAINT `FK_civicrm_relationship_cache_case_id` FOREIGN KEY (`case_id`) REFERENCES `civicrm_case` (`id`) ON DELETE CASCADE)]
  
  ```
  
  **Tags:** upgrade
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-12-11. Score: 1
  
  Looks like a data integrity issue. civicrm\_relationship\_cache table has CiviCase data which is deleted, Will need to clear those first by running below query and re-run the upgrade.
  
  ```
  DELETE crc.* FROM civicrm_relationship_cache crc
  LEFT JOIN civicrm_case cc
    ON crc.case_id = cc.id 
  WHERE cc.id IS NULL AND crc.case_id IS NOT NULL
  
  ```
  
  HTH
  
  username_1
  
  > **Comments:**
  > **username_0**: Absolutely genius!!!!  
  
  ---
  
  