2

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?

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.

  • 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] (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? – Tenz Oct 4 '15 at 18:20
  • 2
    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. – Coleman Oct 5 '15 at 0:58
  • 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. – Tenz Oct 13 '15 at 1:36
  • 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] (drupal.org/node/2592827). – Tenz Oct 14 '15 at 19:07

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.