Getting constraint violation error during event registration. I found that, this error happening when it's saving the custom field value after saving participant info. There is a post hook in my custom module, in that i have code(civicrm_api("Relationship", "create",$params)) to create relationship for contact, if i comment that line it's working fine. Current version am using is CiviCRM 4.6.2. This issue was not there with my previous version 4.3.5.

Can we not use create-api in post hook?

Please suggest.

  • Please edit your question to include the actual code snippet that you believe is causing the error, as well as the full error message itself. – Nicholai Aug 6 '15 at 18:02
  • I have pasted the code as multiple comment since it's not allowing to past all code at once, #0 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\Error.php(182): CRM_Core_Error::backtrace() #1 [internal function](): CRM_Core_Error::handle(Object(DB_Error)) #2 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\PEAR.php(931): call_user_func((Array:2), Object(DB_Error)) #3 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\DB.php(976): PEAR_Error->PEAR_Error("DB Error: constraint violation", -3, 16, (Array:2), "INSERT INTO civicrm_value_health_information_55 ( please_list_any_p...") – user1536854 Aug 7 '15 at 5:10
  • #4 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\PEAR.php(564): DB_Error->DB_Error(-3, 16, (Array:2), "INSERT INTO civicrm_value_health_information_55 ( please_list_any_p...") #5 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\DB\common.php(1905): PEAR->raiseError(NULL, -3, NULL, NULL, "INSERT INTO civicrm_value_health_information_55 ( please_list_any_p...", "DB_Error", TRUE) #6 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\DB\mysql.php(899): DB_common->raiseError(-3, NULL, NULL, NULL, "1452 ** Cannot add or update a child row: a foreign key constraint fails (`ha...") – user1536854 Aug 7 '15 at 5:12
  • #7 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\DB\mysql.php(328): DB_mysql->mysqlRaiseError() #8 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\DB\common.php(1216): DB_mysql->simpleQuery("INSERT IN #9 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\DB\DataObject.php(2442): DB_common->query("INSERT INTO civicrm_value_health_information_55 ( please_list_any_p...") – user1536854 Aug 7 '15 at 5:13
  • #10 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\DB\DataObject.php(1634): DB_DataObject->_query("INSERT INTO civicrm_value_health_information_55 ( please_list_any_p...") #11 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\DAO.php(325): DB_DataObject->query("INSERT INTO civicrm_value_health_information_55 ( please_list_any_p...") #12 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\DAO.php(1179): CRM_Core_DAO->query("INSERT INTO civicrm_value_health_information_55 ( please_list_any_p...", TRUE) – user1536854 Aug 7 '15 at 5:14

If your hook relies on $objectRef being populated, check whether it actually is - they aren't always. See Should civicrm_post hook receive populated Relationship object following relationship enable/disable in UI?

| improve this answer | |

You probably need to do some debugging as to why it is happening. If you turn back-trace & debugging on (debugging is an option under administer/system settings) you should be able to see the failing query and the backtrace. If you can't interpret them you should paste them back here

| improve this answer | |

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.