1

This is on CiviCRM 4.7.13 and WP 4.6.1.

I can add custom fields and custom data sets, but any attempt to delete a custom field hangs and does not complete. The log then contains this:

Nov 05 11:47:00  [info] $Fatal Error Details = Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => handle
        )

    [code] => -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => DELETE FROM civicrm_custom_field  WHERE (  civicrm_custom_field.id = 10 )  [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`yfc_civicrm`.`civicrm_custom_value`, CONSTRAINT `FK_civicrm_custom_value_custom_field_id` FOREIGN KEY (`custom_field_id`) REFERENCES `civicrm_custom_field` (`id`))]
    [type] => DB_Error
    [user_info] => DELETE FROM civicrm_custom_field  WHERE (  civicrm_custom_field.id = 10 )  [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`yfc_civicrm`.`civicrm_custom_value`, CONSTRAINT `FK_civicrm_custom_value_custom_field_id` FOREIGN KEY (`custom_field_id`) REFERENCES `civicrm_custom_field` (`id`))]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="DELETE FROM civicrm_custom_field  WHERE (  civicrm_custom_field.id = 10 )  [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`yfc_civicrm`.`civicrm_custom_value`, CONSTRAINT `FK_civicrm_custom_value_custom_field_id` FOREIGN KEY (`custom_field_id`) REFERENCES `civicrm_custom_field` (`id`))]"]
)


Nov 05 11:47:00  [info] $backTrace = #0 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php(229): CRM_Core_Error::backtrace("backTrace", TRUE)
#1 [internal function](): CRM_Core_Error::handle(Object(DB_Error))
#2 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/PEAR.php(921): call_user_func((Array:2), Object(DB_Error))
#3 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/DB.php(985): PEAR_Error->__construct("DB Error: constraint violation", -3, 16, (Array:2), "DELETE FROM civicrm_custom_field  WHERE (  civicrm_custom_field.id = 10 )  [n...")
#4 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/PEAR.php(575): DB_Error->__construct(-3, 16, (Array:2), "DELETE FROM civicrm_custom_field  WHERE (  civicrm_custom_field.id = 10 )  [n...")
#5 [internal function](): PEAR->_raiseError(Object(DB_mysqli), NULL, -3, NULL, NULL, "DELETE FROM civicrm_custom_field  WHERE (  civicrm_custom_field.id = 10 )  [n...", "DB_Error", TRUE)
#6 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/PEAR.php(224): call_user_func_array((Array:2), (Array:8))
#7 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1905): PEAR->__call("raiseError", (Array:7))
#8 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1905): PEAR->raiseError(NULL, -3, NULL, NULL, "DELETE FROM civicrm_custom_field  WHERE (  civicrm_custom_field.id = 10 )  [n...", "DB_Error", TRUE)
#9 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/DB/mysqli.php(933): DB_common->raiseError(-3, NULL, NULL, NULL, "1451 ** Cannot delete or update a parent row: a foreign key constraint fails ...")
#10 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/DB/mysqli.php(403): DB_mysqli->mysqliRaiseError()
#11 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1216): DB_mysqli->simpleQuery("DELETE FROM civicrm_custom_field  WHERE (  civicrm_custom_field.id = 10 ) ")
#12 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/DB/DataObject.php(2438): DB_common->query("DELETE FROM civicrm_custom_field  WHERE (  civicrm_custom_field.id = 10 ) ")
#13 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/DB/DataObject.php(1449): DB_DataObject->_query("DELETE FROM civicrm_custom_field  WHERE (  civicrm_custom_field.id = 10 ) ")
#14 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/DAO.php(524): DB_DataObject->delete(FALSE)
#15 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/CustomField.php(1128): CRM_Core_DAO->delete()
#16 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Custom/Form/DeleteField.php(104): CRM_Core_BAO_CustomField::deleteField(Object(CRM_Core_DAO_CustomField))
#17 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Form.php(431): CRM_Custom_Form_DeleteField->postProcess()
#18 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/StateMachine.php(160): CRM_Core_Form->mainProcess()
#19 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/QuickForm/Action/Next.php(61): CRM_Core_StateMachine->perform(Object(CRM_Custom_Form_DeleteField), "next", "Next")
#20 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/HTML/QuickForm/Controller.php(203): CRM_Core_QuickForm_Action_Next->perform(Object(CRM_Custom_Form_DeleteField), "next")
#21 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/packages/HTML/QuickForm/Page.php(103): HTML_QuickForm_Controller->handle(Object(CRM_Custom_Form_DeleteField), "next")
#22 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Controller.php(351): HTML_QuickForm_Page->handle("next")
#23 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Custom/Page/Field.php(264): CRM_Core_Controller->run()
#24 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(312): CRM_Custom_Page_Field->run((Array:5), NULL)
#25 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(86): CRM_Core_Invoke::runItem((Array:14))
#26 /home/user/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(54): CRM_Core_Invoke::_invoke((Array:5))
#27 /home/user/wordpress/wp-content/plugins/civicrm/civicrm.php(1227): CRM_Core_Invoke::invoke((Array:5))
#28 [internal function](): CiviCRM_For_WordPress->invoke("")
#29 /home/user/wordpress/wp-includes/plugin.php(524): call_user_func_array((Array:2), (Array:1))
#30 /home/user/wordpress/wp-admin/admin.php(222): do_action("toplevel_page_CiviCRM")
#31 {main}

I'm concerned that the DB is mangled somehow. Any suggestions?

Edit: @Sleewok - Yes.

I have been working with the schema harmonizer and finding that it does not check the custom data tables. How does one determine if there are schema errors in custom data?

  • I know this may be obvious, but have you fully cleared all caches? – Sleewok Nov 7 '16 at 16:31
1

Congratulations on your very long-lived CiviCRM installation! You're seeing a problem that very few will.

civicrm_custom_value is a table that hasn't existed in CiviCRM since around version 2.0. If you do a Google search, you'll only find references to it from around 2007-2009. There are no references to it in the 4.7 code base.

Somewhere along the line, this database missed some piece of code that removed this table. Or more likely, someone restored a backup sometime last decade that brought the table in after it should have been gone. And there it stayed until one day its foreign key constraints tripped you up.

I would back up your database, then delete the civicrm_custom_value table.

  • Yes that is true and deleting that field helps. It has other issues, but I will post separately about those. – user260078 Nov 9 '16 at 5:15
  • Please mark the question as solved if this resolved it! – Jon G - Megaphone Tech Nov 9 '16 at 23:22

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.