Answers.Body: <p>In Civi, if you use &quot;Advanced Search&quot; there is an option to Search in Trash which contains deleted contacts. Contacts that have been deleted during the merging process should show up there. You can leave the other search options blank in order to see all previously deleted contacts too. No need to go through the tables in phpmyadmin.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-18T17:08:27.113Z
Answers.Text: Unfortunately, not there either. Record is completely gone.
Answers.UserDisplayName: themak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-17T16:26:37.143Z
Answers.LastActivityDate: 2022-06-17T16:28:52.447Z
Answers.LastEditDate: 2022-06-17T16:28:52.447Z
Answers.UserDisplayName: PoHo
Body: <p>So here is the issue - that I think was caused by a merger of contacts without transferring the related fields to the new contact. I have a contact, that seems to be missing a large number of historical records.</p>
  <p>I managed to track down their old contact record ID (13) by having them send me some old emails and found all their old records using phpmyadmin by searching for 13 in column &quot;contact_ID&quot; in all tables.</p>
  <p>Contact ID 13 does not exist in the database.</p>
  <p>Can I create a new contact in CiviCRM and then change its ID via phpmyadmin to 13, will it automatically &quot;reconnect&quot; all the records to this newly created contact?</p>
  <p>Edit: tried this, got the following error: #1451 - Cannot delete or update a parent row: a foreign key constraint fails</p>
  <pre><code>(`database_name`.`civicrm_address`, CONSTRAINT `FK_civicrm_address_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)
  </code></pre>
  <p>Or should I just create a contact manually in civicrm_contact via phpmyadmin and set its id value to 13?</p>
  <p>Edit: would I have to create a new hash?</p>
  <p>Would either of these options work?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-16T19:51:57.110Z
Comments.Text: interesting idea (the first one i mean). you may still be missing lots of other data as i theory data in other tables that reference your deleted contact should also have been deleted. so curious about what tables didn't clear the data out. if you have logging on the the data should be recorded in the log tables but is more painful to reconstruct
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-16T19:53:04.453Z
Comments.Text: there is also a risk that when you create your new contact, more rows with the new contact_ID will be created and those will potentially get orphaned when you do your switcheroo on the contact ID
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-16T20:31:49.950Z
Comments.Text: So #1 did not work - I am also unsure about #2 because of the hash - would I just have to generate another random hash?
Comments.UserDisplayName: themak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-16T20:35:04.443Z
Comments.Text: Also you are right - they are all in the log, not in the main database fields, so none of that would work - this is going to be a pain. 
  
  Is there a guide on how to restore data from logs?
Comments.UserDisplayName: themak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-21T17:29:43.753Z
Comments.Text: I managed to restore all these records via the logs, it was exhausting, but im glad its resolved.
Comments.UserDisplayName: themak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-22T18:59:12.170Z
Comments.Text: it would be nice to have a way to be able to do a 'restore' for a specified contact from a db backup - but i imagine it would take some considerable thinking through - though then again - maybe most of the bits have already been done for ensuring all data related to the contact is deleted when one does a permanent delete (and then do the reverse?)
Comments.UserDisplayName: petednz - fuzion
Tags: <contacts><database><duplicate-contacts><mysql>
Title: Possible Deleted Contact - Trying to Restore Records - Possible SQL Solution?
ThreadText: # Possible Deleted Contact - Trying to Restore Records - Possible SQL Solution?
  
  (Asked by: username_0 on 2022-06-16)
  
  So here is the issue - that I think was caused by a merger of contacts without transferring the related fields to the new contact. I have a contact, that seems to be missing a large number of historical records.
  I managed to track down their old contact record ID (13) by having them send me some old emails and found all their old records using phpmyadmin by searching for 13 in column "contact_ID" in all tables.
  Contact ID 13 does not exist in the database.
  Can I create a new contact in CiviCRM and then change its ID via phpmyadmin to 13, will it automatically "reconnect" all the records to this newly created contact?
  Edit: tried this, got the following error: #1451 - Cannot delete or update a parent row: a foreign key constraint fails
  (`database_name`.`civicrm_address`, CONSTRAINT `FK_civicrm_address_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)
  
  Or should I just create a contact manually in civicrm_contact via phpmyadmin and set its id value to 13?
  Edit: would I have to create a new hash?
  Would either of these options work?
  
  **Tags:** contacts, database, duplicate-contacts, mysql
  
  > **Comments:**
  > **username_1**: interesting idea (the first one i mean). you may still be missing lots of other data as i theory data in other tables that reference your deleted contact should also have been deleted. so curious about what tables didn't clear the data out. if you have logging on the the data should be recorded in the log tables but is more painful to reconstruct  
  > **username_1**: there is also a risk that when you create your new contact, more rows with the new contact_ID will be created and those will potentially get orphaned when you do your switcheroo on the contact ID  
  > **username_0**: So #1 did not work - I am also unsure about #2 because of the hash - would I just have to generate another random hash?  
  > **username_0**: Also you are right - they are all in the log, not in the main database fields, so none of that would work - this is going to be a pain.   Is there a guide on how to restore data from logs?  
  > **username_0**: I managed to restore all these records via the logs, it was exhausting, but im glad its resolved.  
  > **username_1**: it would be nice to have a way to be able to do a 'restore' for a specified contact from a db backup - but i imagine it would take some considerable thinking through - though then again - maybe most of the bits have already been done for ensuring all data related to the contact is deleted when one does a permanent delete (and then do the reverse?)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-06-17. Score: 0
  
  In Civi, if you use "Advanced Search" there is an option to Search in Trash which contains deleted contacts. Contacts that have been deleted during the merging process should show up there. You can leave the other search options blank in order to see all previously deleted contacts too. No need to go through the tables in phpmyadmin.
  
  > **Comments:**
  > **username_0**: Unfortunately, not there either. Record is completely gone.  
  
  ---
  
  