Answers.Body: <p>From the backtrace, it appears that the contact has already been created by the time the logging error happens. Since the API uses rollbacks, the error inserting into the log probably forces the contact crete to be rolled back, thus deleting the new contact.</p>
  
  <p>Seems like something is wrong with your logging schema. One easy solution might be to switch to advanced logging, which is a recommended setting anyway, and ditch the simple logging and whatever bug it's got in it.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-04T18:20:18.227Z
Answers.Text: Thanks, that explains a lot! I didn't realise the API had rollbacks. I had a look at enabling advanced logging, but the radio buttons are disabled. Presumably because this is a multilingual site. It looks like advanced logging has [just been fixed for multilingual site in 4.7]  (https://issues.civicrm.org/jira/browse/CRM-12658). Since that's still alpha, can I disable the regular logging somehow? Can I just drop civicrm_log?
Answers.UserDisplayName: Tenz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-05T00:58:12.517Z
Answers.Text: I really don't think dropping one of civicrm's tables will help with your stability problem (more likely it will cause a lot more errors). But this is the first time you mentioned that it's a multilingual site and that might be relevant. It would  be good to try to reproduce this on a clean install with and without multilingual enabled.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-13T01:36:42.140Z
Answers.Text: Grr. Switching to single language causes a missing table error, so I can’t explore that. Strangely, just duplicating the Drupal database allows normal creation of contacts. But deleting that contact (permanently) causes the original issue to recur. I noticed in civicrm_log that the “modified_id” field is the previous contact’s ID, which seems bizarre/wrong. Banging my head against the wall.
Answers.UserDisplayName: Tenz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-14T19:07:44.603Z
Answers.Text: Just tried this on a fresh install on a local server. Same issue. Switched from multilingual to single language and turned on advanced logging, but same situation. I've filed a bug report [here] (https://www.drupal.org/node/2592827).
Answers.UserDisplayName: Tenz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-03T18:25:33.063Z
Answers.LastActivityDate: 2015-10-03T18:25:33.063Z
Answers.UserDisplayName: Coleman
Body: <p>Something is not right with my webform civicrm installation (version 7.x-4.12 with webform 7.x-4.11, CiviCRM 4.5.4). Creating a contact (even with one field included) fails, with this constraint violation logged:</p>
  
  <pre><code>The CiviCRM "contact create" API function returned the error: "DB Error: constraint violation" when called by line 589 of wf_crm_webform_postprocess.inc with the following parameters: "Array ( [contact_type] =&gt; Individual [contact_sub_type] =&gt; Array ( ) [webform_label] =&gt; Contact 1 [first_name] =&gt; Test [last_name] =&gt; Test [source] =&gt; Test [check_permissions] =&gt; [version] =&gt; 3 ) "
  </code></pre>
  
  <p>webform civicrm works fine updating existing contacts. Looking at the CiviCRM backtrace, the errors begin with inserting into civicrm_log because there isn't a corresponding id in civicrm_contact, since the contact hasn't been created. Here's a backtrace:</p>
  
  <pre><code>Oct 02 02:25:31  [info] $backTrace = #0 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/CRM/Core/Error.php(866): CRM_Core_Error::backtrace("backTrace", TRUE)
  #1 [internal function](): CRM_Core_Error::exceptionHandler(Object(DB_Error))
  #2 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/PEAR.php(931): call_user_func((Array:2), Object(DB_Error))
  #3 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB.php(975): PEAR_Error-&gt;PEAR_Error("DB Error: constraint violation", -3, 16, (Array:2), "INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key...")
  #4 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/PEAR.php(564): DB_Error-&gt;DB_Error(-3, 16, (Array:2), "INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key...")
  #5 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB/common.php(1905): PEAR-&gt;raiseError(NULL, -3, NULL, NULL, "INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key...", "DB_Error", TRUE)
  #6 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB/mysql.php(899): DB_common-&gt;raiseError(-3, NULL, NULL, NULL, "1452 ** Cannot add or update a child row: a foreign key constraint fails (`aca_civicrm_v2`.`civicrm_log`, CONSTRAINT `FK_civicrm_log_modified_id` FOREIGN KEY (`modified_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)")
  #7 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB/mysql.php(328): DB_mysql-&gt;mysqlRaiseError()
  #8 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB/common.php(1216): DB_mysql-&gt;simpleQuery("INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 ) ")
  #9 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB/DataObject.php(2442): DB_common-&gt;query("INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 ) ")
  #10 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB/DataObject.php(1060): DB_DataObject-&gt;_query("INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 ) ")
  #11 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/CRM/Core/DAO.php(455): DB_DataObject-&gt;insert()
  #12 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/CRM/Core/BAO/Log.php(139): CRM_Core_DAO-&gt;save()
  #13 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/CRM/Contact/BAO/Contact.php(233): CRM_Core_BAO_Log::register(23217, "civicrm_contact", 23217)
  #14 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/CRM/Contact/BAO/Contact.php(320): CRM_Contact_BAO_Contact::add((Array:14))
  #15 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/api/v3/Contact.php(409): CRM_Contact_BAO_Contact::create((Array:14))
  #16 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/api/v3/Contact.php(103): _civicrm_api3_contact_update((Array:9), NULL)
  #17 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(86): civicrm_api3_contact_create((Array:8))
  #18 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/Civi/API/Kernel.php(95): Civi\API\Provider\MagicFunctionProvider-&gt;invoke((Array:9))
  #19 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/api/api.php(25): Civi\API\Kernel-&gt;run("contact", "create", (Array:8), NULL)
  #20 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform_civicrm/includes/utils.inc(1473): civicrm_api("contact", "create", (Array:8))
  #21 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform_civicrm/includes/wf_crm_webform_postprocess.inc(610): wf_civicrm_api("contact", "create", (Array:6))
  #22 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform_civicrm/includes/wf_crm_webform_postprocess.inc(143): wf_crm_webform_postprocess-&gt;createContact((Array:16))
  #23 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform_civicrm/webform_civicrm.module(205): wf_crm_webform_postprocess-&gt;preSave(Object(stdClass))
  #24 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform/includes/webform.submissions.inc(147): webform_civicrm_webform_submission_presave(Object(stdClass), Object(stdClass))
  #25 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform/webform.module(3298): webform_submission_insert(Object(stdClass), Object(stdClass))
  #26 /var/www/vhosts/mydomain.com/site/includes/form.inc(1513): webform_client_form_submit((Array:33), (Array:24))
  #27 /var/www/vhosts/mydomain.com/site/includes/form.inc(903): form_execute_handlers("submit", (Array:33), (Array:24))
  #28 /var/www/vhosts/mydomain.com/site/includes/form.inc(385): drupal_process_form("webform_client_form_1633", (Array:33), (Array:24))
  #29 /var/www/vhosts/mydomain.com/site/includes/form.inc(130): drupal_build_form("webform_client_form_1633", (Array:24))
  #30 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform/webform.module(1986): drupal_get_form("webform_client_form_1633", Object(stdClass), FALSE, FALSE)
  #31 [internal function](): webform_node_view(Object(stdClass), "full", "en")
  #32 /var/www/vhosts/mydomain.com/site/includes/module.inc(895): call_user_func_array("webform_node_view", (Array:3))
  #33 /var/www/vhosts/mydomain.com/site/modules/node/node.module(1440): module_invoke_all("node_view", Object(stdClass), "full", "en")
  #34 /var/www/vhosts/mydomain.com/site/modules/node/node.module(1335): node_build_content(Object(stdClass), "full", "en")
  #35 /var/www/vhosts/mydomain.com/site/modules/node/node.module(2670): node_view(Object(stdClass), "full", NULL)
  #36 /var/www/vhosts/mydomain.com/site/modules/node/node.module(1465): node_view_multiple((Array:1), "full")
  #37 /var/www/vhosts/mydomain.com/site/modules/node/node.module(2762): node_show(Object(stdClass))
  #38 [internal function](): node_page_view(Object(stdClass))
  #39 /var/www/vhosts/mydomain.com/site/includes/menu.inc(517): call_user_func_array("node_page_view", (Array:1))
  #40 /var/www/vhosts/mydomain.com/site/index.php(21): menu_execute_active_handler()
  #41 {main}
  </code></pre>
  
  <p>Using CiviCRM API explorer there is no problem adding a new contact with the same parameters. I don't see any MySQL/PHP errors in the logs.</p>
  
  <p>There is at least one other person experiencing a <a href="https://www.drupal.org/node/2390127" rel="nofollow">similar error</a>, although he has narrowed the issue down to the <a href="https://www.drupal.org/node/2578489" rel="nofollow">name prefix field</a>, which I am not using in my test forms.</p>
  
  <p>What else should I be looking at to troubleshoot this?</p>
  
Tags: <api><contacts><webform-civicrm>
Title: Webform civicrm not creating contacts
ThreadText: # Webform civicrm not creating contacts
  
  (Asked by: username_0 on 2015-10-03)
  
  Something is not right with my webform civicrm installation (version 7.x-4.12 with webform 7.x-4.11, CiviCRM 4.5.4). Creating a contact (even with one field included) fails, with this constraint violation logged:
  The CiviCRM "contact create" API function returned the error: "DB Error: constraint violation" when called by line 589 of wf_crm_webform_postprocess.inc with the following parameters: "Array ( [contact_type] => Individual [contact_sub_type] => Array ( ) [webform_label] => Contact 1 [first_name] => Test [last_name] => Test [source] => Test [check_permissions] => [version] => 3 ) "
  
  webform civicrm works fine updating existing contacts. Looking at the CiviCRM backtrace, the errors begin with inserting into civicrm_log because there isn't a corresponding id in civicrm_contact, since the contact hasn't been created. Here's a backtrace:
  Oct 02 02:25:31  [info] $backTrace = #0 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/CRM/Core/Error.php(866): CRM_Core_Error::backtrace("backTrace", TRUE)
  #1 [internal function](): CRM_Core_Error::exceptionHandler(Object(DB_Error))
  #2 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/PEAR.php(931): call_user_func((Array:2), Object(DB_Error))
  #3 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB.php(975): PEAR_Error->PEAR_Error("DB Error: constraint violation", -3, 16, (Array:2), "INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key...")
  #4 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/PEAR.php(564): DB_Error->DB_Error(-3, 16, (Array:2), "INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key...")
  #5 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB/common.php(1905): PEAR->raiseError(NULL, -3, NULL, NULL, "INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key...", "DB_Error", TRUE)
  #6 /var/www/vhosts/mydomain.com/site/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 (`aca_civicrm_v2`.`civicrm_log`, CONSTRAINT `FK_civicrm_log_modified_id` FOREIGN KEY (`modified_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)")
  #7 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB/mysql.php(328): DB_mysql->mysqlRaiseError()
  #8 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB/common.php(1216): DB_mysql->simpleQuery("INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 ) ")
  #9 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB/DataObject.php(2442): DB_common->query("INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 ) ")
  #10 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/packages/DB/DataObject.php(1060): DB_DataObject->_query("INSERT INTO civicrm_log (entity_table , entity_id , data , modified_id , modified_date ) VALUES ('civicrm_contact' ,  23217 , 'civicrm_contact,23217' ,  23181 ,  20151002022531 ) ")
  #11 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/CRM/Core/DAO.php(455): DB_DataObject->insert()
  #12 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/CRM/Core/BAO/Log.php(139): CRM_Core_DAO->save()
  #13 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/CRM/Contact/BAO/Contact.php(233): CRM_Core_BAO_Log::register(23217, "civicrm_contact", 23217)
  #14 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/CRM/Contact/BAO/Contact.php(320): CRM_Contact_BAO_Contact::add((Array:14))
  #15 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/api/v3/Contact.php(409): CRM_Contact_BAO_Contact::create((Array:14))
  #16 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/api/v3/Contact.php(103): _civicrm_api3_contact_update((Array:9), NULL)
  #17 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(86): civicrm_api3_contact_create((Array:8))
  #18 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/Civi/API/Kernel.php(95): Civi\API\Provider\MagicFunctionProvider->invoke((Array:9))
  #19 /var/www/vhosts/mydomain.com/site/sites/all/modules/civicrm/api/api.php(25): Civi\API\Kernel->run("contact", "create", (Array:8), NULL)
  #20 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform_civicrm/includes/utils.inc(1473): civicrm_api("contact", "create", (Array:8))
  #21 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform_civicrm/includes/wf_crm_webform_postprocess.inc(610): wf_civicrm_api("contact", "create", (Array:6))
  #22 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform_civicrm/includes/wf_crm_webform_postprocess.inc(143): wf_crm_webform_postprocess->createContact((Array:16))
  #23 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform_civicrm/webform_civicrm.module(205): wf_crm_webform_postprocess->preSave(Object(stdClass))
  #24 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform/includes/webform.submissions.inc(147): webform_civicrm_webform_submission_presave(Object(stdClass), Object(stdClass))
  #25 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform/webform.module(3298): webform_submission_insert(Object(stdClass), Object(stdClass))
  #26 /var/www/vhosts/mydomain.com/site/includes/form.inc(1513): webform_client_form_submit((Array:33), (Array:24))
  #27 /var/www/vhosts/mydomain.com/site/includes/form.inc(903): form_execute_handlers("submit", (Array:33), (Array:24))
  #28 /var/www/vhosts/mydomain.com/site/includes/form.inc(385): drupal_process_form("webform_client_form_1633", (Array:33), (Array:24))
  #29 /var/www/vhosts/mydomain.com/site/includes/form.inc(130): drupal_build_form("webform_client_form_1633", (Array:24))
  #30 /var/www/vhosts/mydomain.com/site/sites/all/modules/webform/webform.module(1986): drupal_get_form("webform_client_form_1633", Object(stdClass), FALSE, FALSE)
  #31 [internal function](): webform_node_view(Object(stdClass), "full", "en")
  #32 /var/www/vhosts/mydomain.com/site/includes/module.inc(895): call_user_func_array("webform_node_view", (Array:3))
  #33 /var/www/vhosts/mydomain.com/site/modules/node/node.module(1440): module_invoke_all("node_view", Object(stdClass), "full", "en")
  #34 /var/www/vhosts/mydomain.com/site/modules/node/node.module(1335): node_build_content(Object(stdClass), "full", "en")
  #35 /var/www/vhosts/mydomain.com/site/modules/node/node.module(2670): node_view(Object(stdClass), "full", NULL)
  #36 /var/www/vhosts/mydomain.com/site/modules/node/node.module(1465): node_view_multiple((Array:1), "full")
  #37 /var/www/vhosts/mydomain.com/site/modules/node/node.module(2762): node_show(Object(stdClass))
  #38 [internal function](): node_page_view(Object(stdClass))
  #39 /var/www/vhosts/mydomain.com/site/includes/menu.inc(517): call_user_func_array("node_page_view", (Array:1))
  #40 /var/www/vhosts/mydomain.com/site/index.php(21): menu_execute_active_handler()
  #41 {main}
  
  Using CiviCRM API explorer there is no problem adding a new contact with the same parameters. I don't see any MySQL/PHP errors in the logs.
  There is at least one other person experiencing a similar error, although he has narrowed the issue down to the name prefix field, which I am not using in my test forms.
  What else should I be looking at to troubleshoot this?
  
  **Tags:** api, contacts, webform-civicrm
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-10-03. Score: 2
  
  From the backtrace, it appears that the contact has already been created by the time the logging error happens. Since the API uses rollbacks, the error inserting into the log probably forces the contact crete to be rolled back, thus deleting the new contact.
  
  Seems like something is wrong with your logging schema. One easy solution might be to switch to advanced logging, which is a recommended setting anyway, and ditch the simple logging and whatever bug it's got in it.
  
  > **Comments:**
  > **username_0**: Thanks, that explains a lot! I didn't realise the API had rollbacks. I had a look at enabling advanced logging, but the radio buttons are disabled. Presumably because this is a multilingual site. It looks like advanced logging has [just been fixed for multilingual site in 4.7]  (https://issues.civicrm.org/jira/browse/CRM-12658). Since that's still alpha, can I disable the regular logging somehow? Can I just drop civicrm_log?  
  > **username_1**: I really don't think dropping one of civicrm's tables will help with your stability problem (more likely it will cause a lot more errors). But this is the first time you mentioned that it's a multilingual site and that might be relevant. It would  be good to try to reproduce this on a clean install with and without multilingual enabled.  
  > **username_0**: Grr. Switching to single language causes a missing table error, so I can’t explore that. Strangely, just duplicating the Drupal database allows normal creation of contacts. But deleting that contact (permanently) causes the original issue to recur. I noticed in civicrm_log that the “modified_id” field is the previous contact’s ID, which seems bizarre/wrong. Banging my head against the wall.  
  > **username_0**: Just tried this on a fresh install on a local server. Same issue. Switched from multilingual to single language and turned on advanced logging, but same situation. I've filed a bug report [here] (https://www.drupal.org/node/2592827).  
  
  ---
  
  