Answers.Body: <p>You're probably missing a foreign key in your schema. I'm not seeing it work like you describe, and if you <code>SHOW CREATE TABLE civicrm_relationship</code>, do you see these?</p>
  <pre><code>CONSTRAINT `FK_civicrm_relationship_contact_id_a` FOREIGN KEY (`contact_id_a`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE,
  CONSTRAINT `FK_civicrm_relationship_contact_id_b` FOREIGN KEY (`contact_id_b`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE,
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-23T14:19:50.423Z
Answers.Text: Thank you, Demerit, I do see those FK's in the civicrm_relationship table. Should there be some in the civicrm_contact table, as well?
Answers.UserDisplayName: MtnPavlas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-24T13:34:26.943Z
Answers.Text: No there shouldn't be anything related in the contact table, but that's weird that you have them and are still having the problem, because when the contact is removed from the contact table those key constraints should remove the relationship record.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-23T03:37:23.353Z
Answers.LastActivityDate: 2024-10-23T03:37:23.353Z
Answers.UserDisplayName: Demerit
Body: <p>When a contact is <strong>permanently</strong> deleted, the relationships remain in the civicrm_relationship talbe (i.e., they don't get deleted/removed), which then causes issues when the relationship cache table rebuild runs, i.e., it completely farts, and doesn't get built, causing all sorts of issues. Is that just our instance where that happens? Or, are others seeing the same behavior? If so, that's a design flaw, no?</p>
  
Tags: <contacts><relationships><delete>
Title: permanently deleting contact does not remove relationships
ThreadText: # permanently deleting contact does not remove relationships
  
  (Asked by: username_0 on 2024-10-23)
  
  When a contact is **permanently** deleted, the relationships remain in the civicrm\_relationship talbe (i.e., they don't get deleted/removed), which then causes issues when the relationship cache table rebuild runs, i.e., it completely farts, and doesn't get built, causing all sorts of issues. Is that just our instance where that happens? Or, are others seeing the same behavior? If so, that's a design flaw, no?
  
  **Tags:** contacts, relationships, delete
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-10-23. Score: 1
  
  You're probably missing a foreign key in your schema. I'm not seeing it work like you describe, and if you SHOW CREATE TABLE civicrm_relationship, do you see these?
  CONSTRAINT `FK_civicrm_relationship_contact_id_a` FOREIGN KEY (`contact_id_a`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE,
  CONSTRAINT `FK_civicrm_relationship_contact_id_b` FOREIGN KEY (`contact_id_b`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE,
  
  > **Comments:**
  > **username_0**: Thank you, username_1, I do see those FK's in the civicrm_relationship table. Should there be some in the civicrm_contact table, as well?  
  > **username_1**: No there shouldn't be anything related in the contact table, but that's weird that you have them and are still having the problem, because when the contact is removed from the contact table those key constraints should remove the relationship record.  
  
  ---
  
  