2

I have borrowed the title from this unanswered forum post by Laryn: DeDupe errors when Individuals have Membership (by relationship).

Just encountered the same error on a Civi 4.6.9 / Drupal 7 site. Laryn, did you get anywhere with this? Or can anyone shed any light? It appears that CRM_Member_BAO_Membership::createRelatedMemberships(), via some intermediate function calls, tried to insert a civicrm_membership record without specifying membership_type_id: our error & backtrace is very similar to Laryn's:

[debug_info] => INSERT INTO civicrm_membership (contact_id , status_id , owner_membership_id ) VALUES ( 15835 , 2 , 21422 ) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (my_civicrm.civicrm_membership, CONSTRAINT FK_civicrm_membership_membership_type_id FOREIGN KEY (membership_type_id) REFERENCES civicrm_membership_type (id) ON DELETE CASCA)]

Excerpt from backtrace:

#10 .../civicrm/packages/DB/DataObject.php(1060): DB_DataObject->_query("INSERT INTO civicrm_membership (contact_id , status_id , owner_membership_id ...")
#11 .../civicrm/CRM/Core/DAO.php(450): DB_DataObject->insert()
#12 .../civicrm/CRM/Member/BAO/Membership.php(102): CRM_Core_DAO->save()
#13 .../civicrm/CRM/Member/BAO/Membership.php(310): CRM_Member_BAO_Membership::add((Array:6), (Array:0))
#14 .../civicrm/CRM/Member/BAO/Membership.php(1941): CRM_Member_BAO_Membership::create((Array:6), (Array:0))
#15 .../civicrm/CRM/Dedupe/Merger.php(1655): CRM_Member_BAO_Membership::createRelatedMemberships((Array:4), Object(CRM_Member_DAO_Membership))
#16 .../civicrm/CRM/Dedupe/Merger.php(512): CRM_Dedupe_Merger::addMembershipToRealtedContacts(6428)
#17 .../civicrm/CRM/Dedupe/Merger.php(1349): CRM_Dedupe_Merger::moveContactBelongings("6428", "36044")
#18 .../civicrm/CRM/Dedupe/Merger.php(660): CRM_Dedupe_Merger::moveAllBelongings("6428", "36044", (Array:6))
#19 .../civicrm/CRM/Dedupe/Merger.php(596): CRM_Dedupe_Merger::merge((Array:75), (Array:3), "safe", TRUE, TRUE)
#20 .../civicrm/CRM/Contact/Page/DedupeFind.php(97): CRM_Dedupe_Merger::batchMerge("11", "48", "safe", TRUE, TRUE)
#21 .../civicrm/CRM/Core/Invoke.php(312): CRM_Contact_Page_DedupeFind->run((Array:3), NULL)
  • Sorry, I didn't get much traction in the forum post, obviously, and since it didn't seem to happen in the demo site when I tried to test there, I assumed it was something in our database. We muddled through these and have recently ended up regenerating all shared memberships to make sure those were up to speed after some fiddling in the database: civicrm.stackexchange.com/questions/4703/… – Laryn - CEDC.org Nov 2 '15 at 17:33
  • Hi Laryn, thanks for the response. Did regenerating the inherited memberships resolve the problem? – davejenx Nov 3 '15 at 10:33
2

We have had a similar problem - https://gist.githubusercontent.com/deepak-srivastava/e3a440023621cd4ecbde3904f9b27d2c/raw/7d2e854aa4ad7a8f00d87581dca729623d5ba687/bto-membership-by-relationship-error.log

Seems like method createRelatedMemberships(&$params, &$dao, $reset = FALSE) in loop sometimes resets $params. The while loop at the end of the function seems to be the cause. Don't see why anything from queue should reset it.

Have developed a patch - https://github.com/deepak-srivastava/civicrm-core/commit/96fba9b2533b45d9baaef8b0f7ea43bc85ae0ee9

Seems to be working so far. We 'll test it a bit more, and if ok submit a PR to core. Meanwhile would you be able to confirm if the patch works for you?

  • Hi Deepak, thanks for this and sorry for the slow response. The problem was occurring on one client's site two years ago and I wasn't able to replicate it (without the patch) when I tried after reading your answer. We have asked the client whether they have encountered the problem recently but so far have had no response. I'll update here if we hear anything. – davejenx Aug 31 '17 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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