Answers.Body: <p>If your hook relies on $objectRef being populated, check whether it actually is - they aren't always. See <a href="https://civicrm.stackexchange.com/questions/3901/should-civicrm-post-hook-receive-populated-relationship-object-following-relatio">Should civicrm_post hook receive populated Relationship object following relationship enable/disable in UI?</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-06T09:24:01.800Z
Answers.LastActivityDate: 2015-08-06T09:24:01.800Z
Answers.LastEditDate: 2017-04-13T12:53:13.207Z
Answers.UserDisplayName: davejenx
Answers.Body: <p>You probably need to do some debugging as to why it is happening. If you turn back-trace &amp; 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</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-06T08:49:32.327Z
Answers.LastActivityDate: 2015-08-06T08:49:32.327Z
Answers.UserDisplayName: eileen
Body: <p>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(<strong>civicrm_api("Relationship", "create",$params)</strong>) 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.</p>
  
  <p>Can we not use create-api in post hook?</p>
  
  <p>Please suggest.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-06T18:02:25.500Z
Comments.Text: 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.
Comments.UserDisplayName: Nicholai
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-07T05:10:35.753Z
Comments.Text: 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...")
Comments.UserDisplayName: user1536854
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-07T05:12:34.340Z
Comments.Text: #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...")
Comments.UserDisplayName: user1536854
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-07T05:13:16.227Z
Comments.Text: #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...")
Comments.UserDisplayName: user1536854
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-07T05:14:45.123Z
Comments.Text: #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)
Comments.UserDisplayName: user1536854
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-07T05:15:06.007Z
Comments.Text: #13 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\BAO\CustomValueTable.php(241): CRM_Core_DAO::executeQuery("INSERT INTO civicrm_value_health_information_55  ( please_list_any_p...", (Array:4))
  #14 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\BAO\CustomValueTable.php(349): CRM_Core_BAO_CustomValueTable::create((Array:3))
  #15 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\BAO\CustomValueTable.php(370): CRM_Core_BAO_CustomValueTable::store((Array:34), "civicrm_participant", 5148)
Comments.UserDisplayName: user1536854
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-07T05:15:49.993Z
Comments.Text: #17 D:\wamp\www\mysite\sites\all\modules\my_custom\civicrm\CRM\Event\Form\Registration\Confirm.php(1015): CRM_Event_Form_Registration->confirmPostProcess("1", Object(CRM_Contribute_BAO_Contribution), Object(CRM_Core_Payment_PayPalImpl))
  #18 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\Form.php(345): CRM_Event_Form_Registration_Confirm->postProcess()
Comments.UserDisplayName: user1536854
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-07T05:16:13.840Z
Comments.Text: #19 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\StateMachine.php(164): CRM_Core_Form->mainProcess()
  #20 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\QuickForm\Action\Next.php(61): CRM_Core_StateMachine->perform(Object(CRM_Event_Form_Registration_Confirm), "next", "Next")
  #21 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\HTML\QuickForm\Controller.php(203): CRM_Core_QuickForm_Action_Next->perform(Object(CRM_Event_Form_Registration_Confirm), "next")
Comments.UserDisplayName: user1536854
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-07T05:16:37.463Z
Comments.Text: #22 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\HTML\QuickForm\Page.php(103): HTML_QuickForm_Controller->handle(Object(CRM_Event_Form_Registration_Confirm), "next")
  #23 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\Controller.php(353): HTML_QuickForm_Page->handle("next")
  #24 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\Invoke.php(312): CRM_Core_Controller->run((Array:3), NULL)
  #25 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\Invoke.php(86): CRM_Core_Invoke::runItem((Array:15))
Comments.UserDisplayName: user1536854
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-07T05:21:36.853Z
Comments.Text: **Code in post_hook,**
  
  function customlogic_civicrm_post($op, $objectName, $id, &$params) {
      if ('Participant' == $objectName) {
    $r = civicrm_api("Relationship", "create", array(version => '3', 'sequential' => '1', 'contact_id_a' => $contact_id_1, 'contact_id_b' => $contact_id_2, 'relationship_type_id' => 12));
   }
  }
Comments.UserDisplayName: user1536854
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-07T11:57:34.677Z
Comments.Text: Additional details go in the question, not as comments. Please move the comments into your question, formatted as code. It's currently not very readable in this format.
Comments.UserDisplayName: Nicholai
Tags: <civievent>
Title: constraint violation during event registration
ThreadText: # constraint violation during event registration
  
  (Asked by: username_0 on 2015-08-06)
  
  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.
  
  **Tags:** civievent
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_0**: 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...")  
  > **username_0**: #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...")  
  > **username_0**: #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...")  
  > **username_0**: #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)  
  > **username_0**: #13 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\BAO\CustomValueTable.php(241): CRM_Core_DAO::executeQuery("INSERT INTO civicrm_value_health_information_55  ( please_list_any_p...", (Array:4)) #14 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\BAO\CustomValueTable.php(349): CRM_Core_BAO_CustomValueTable::create((Array:3)) #15 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\BAO\CustomValueTable.php(370): CRM_Core_BAO_CustomValueTable::store((Array:34), "civicrm_participant", 5148)  
  > **username_0**: #17 D:\wamp\www\mysite\sites\all\modules\my_custom\civicrm\CRM\Event\Form\Registration\Confirm.php(1015): CRM_Event_Form_Registration->confirmPostProcess("1", Object(CRM_Contribute_BAO_Contribution), Object(CRM_Core_Payment_PayPalImpl)) #18 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\Form.php(345): CRM_Event_Form_Registration_Confirm->postProcess()  
  > **username_0**: #19 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\StateMachine.php(164): CRM_Core_Form->mainProcess() #20 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\QuickForm\Action\Next.php(61): CRM_Core_StateMachine->perform(Object(CRM_Event_Form_Registration_Confirm), "next", "Next") #21 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\HTML\QuickForm\Controller.php(203): CRM_Core_QuickForm_Action_Next->perform(Object(CRM_Event_Form_Registration_Confirm), "next")  
  > **username_0**: #22 D:\wamp\www\mysite\sites\all\modules\civicrm\packages\HTML\QuickForm\Page.php(103): HTML_QuickForm_Controller->handle(Object(CRM_Event_Form_Registration_Confirm), "next") #23 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\Controller.php(353): HTML_QuickForm_Page->handle("next") #24 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\Invoke.php(312): CRM_Core_Controller->run((Array:3), NULL) #25 D:\wamp\www\mysite\sites\all\modules\civicrm\CRM\Core\Invoke.php(86): CRM_Core_Invoke::runItem((Array:15))  
  > **username_0**: **Code in post_hook,**  function customlogic_civicrm_post($op, $objectName, $id, &$params) {     if ('Participant' == $objectName) {   $r = civicrm_api("Relationship", "create", array(version => '3', 'sequential' => '1', 'contact_id_a' => $contact_id_1, 'contact_id_b' => $contact_id_2, 'relationship_type_id' => 12));  } }  
  > **username_1**: Additional details go in the question, not as comments. Please move the comments into your question, formatted as code. It's currently not very readable in this format.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2015-08-06. Score: 1
  
  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?](https://civicrm.stackexchange.com/questions/3901/should-civicrm-post-hook-receive-populated-relationship-object-following-relatio)
  
  
  ---
  
  ### Answer by username_3 on 2015-08-06. Score: 0
  
  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
  
  
  ---
  
  