3

I am running CiviCRM 5.0.0 on WordPress 4.9.5 and got a DB Constraint Violation each time I try to active/deactivate an extension (after the validation screen) or when I validate the WordPress Access Control panel of CiviCRM. Despite the error message, the required action is completed.

This is an error that is present since some month and therefore some releases (I do not remember when exactly).

The detailed error message:

Apr 18 00:12:41  [info] $Fatal Error Details = Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => exceptionHandler
        )

    [code] => -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] =>
                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, contact_id )
                  VALUES  ( 7, 2 ), ( 7, 9 ), ( 7, 10 ), ( 7, 12 ), ( 7, 13 ), ( 7, 19 ), ( 7, 20 ), ( 7, 21 ), ( 7, 22 ), ( 7, 31 ), ( 7, 36 ), ( 7, 39 ), ( 7, 76 ) [nativecode=1452 ** Cannot add or update a child row: a foreign key const
raint fails (`aquaparismcivi`.`civicrm_dashboard_contact`, CONSTRAINT `FK_civicrm_dashboard_contact_dashboard_id` FOREIGN KEY (`dashboard_id`) REFERENCES `civicrm_dashboard` (`id`) ON DELETE CASCADE)]
    [type] => DB_Error
    [user_info] =>
                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, contact_id )
                  VALUES  ( 7, 2 ), ( 7, 9 ), ( 7, 10 ), ( 7, 12 ), ( 7, 13 ), ( 7, 19 ), ( 7, 20 ), ( 7, 21 ), ( 7, 22 ), ( 7, 31 ), ( 7, 36 ), ( 7, 39 ), ( 7, 76 ) [nativecode=1452 ** Cannot add or update a child row: a foreign key const
raint fails (`aquaparismcivi`.`civicrm_dashboard_contact`, CONSTRAINT `FK_civicrm_dashboard_contact_dashboard_id` FOREIGN KEY (`dashboard_id`) REFERENCES `civicrm_dashboard` (`id`) ON DELETE CASCADE)]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::exceptionHandler prefix="" info="
                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, contact_id )
                  VALUES  ( 7, 2 ), ( 7, 9 ), ( 7, 10 ), ( 7, 12 ), ( 7, 13 ), ( 7, 19 ), ( 7, 20 ), ( 7, 21 ), ( 7, 22 ), ( 7, 31 ), ( 7, 36 ), ( 7, 39 ), ( 7, 76 ) [nativecode=1452 ** Cannot add or update a child row: a foreign key const
raint fails (`aquaparismcivi`.`civicrm_dashboard_contact`, CONSTRAINT `FK_civicrm_dashboard_contact_dashboard_id` FOREIGN KEY (`dashboard_id`) REFERENCES `civicrm_dashboard` (`id`) ON DELETE CASCADE)]"]
)

The trace

Apr 18 00:12:41  [info] $backTrace = #0 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php(948): CRM_Core_Error::backtrace("backTrace", TRUE)
#1 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/PEAR.php(921): CRM_Core_Error::exceptionHandler(Object(DB_Error))
#2 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/DB.php(985): PEAR_Error->__construct("DB Error: constraint violation", -3, 16, (Array:2), "\n                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, con...
")
#3 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/PEAR.php(575): DB_Error->__construct(-3, 16, (Array:2), "\n                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, con...")
#4 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/PEAR.php(223): PEAR->_raiseError(Object(DB_mysqli), NULL, -3, 16, (Array:2), "\n                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, con...", "DB_Error"
, TRUE)
#5 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1905): PEAR->__call("raiseError", (Array:7))
#6 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/DB/mysqli.php(933): DB_common->raiseError(-3, NULL, NULL, "\n                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, con...", "1452 ** Cannot add or update
 a child row: a foreign key constraint fails (`aq...")
#7 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/DB/mysqli.php(403): DB_mysqli->mysqliRaiseError()
#8 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1216): DB_mysqli->simpleQuery("\n                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, con...")
#9 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/DB/DataObject.php(2446): DB_common->query("\n                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, con...")
#10 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/DB/DataObject.php(1635): DB_DataObject->_query("\n                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, con...")
#11 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/DAO.php(392): DB_DataObject->query("\n                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, con...")
#12 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/DAO.php(1348): CRM_Core_DAO->query("\n                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, con...", TRUE)
#13 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/Dashboard.php(467): CRM_Core_DAO::executeQuery("\n                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, con...")
#14 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/Dashboard.php(416): CRM_Core_BAO_Dashboard::addContactDashlet(Object(CRM_Core_DAO_Dashboard))
#15 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/Dashboard.php(50): CRM_Core_BAO_Dashboard::addDashlet((Array:3))
#16 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/api/v3/utils.php(1288): CRM_Core_BAO_Dashboard::create((Array:3), (Array:1))
#17 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/api/v3/Dashboard.php(51): _civicrm_api3_basic_create("CRM_Core_BAO_Dashboard", (Array:3), "Dashboard")
#18 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_dashboard_create((Array:3))
#19 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(169): Civi\API\Provider\MagicFunctionProvider->invoke((Array:9))
#20 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(100): Civi\API\Kernel->runRequest((Array:9))
#21 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/api/api.php(23): Civi\API\Kernel->runSafe("Dashboard", "create", (Array:3), NULL)
#22 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/ManagedEntities.php(290): civicrm_api("Dashboard", "create", (Array:3))
#23 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/ManagedEntities.php(196): CRM_Core_ManagedEntities->disableEntity(Object(CRM_Core_DAO_Managed))
#24 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/ManagedEntities.php(123): CRM_Core_ManagedEntities->reconcileDisabledModules()
#25 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(395): CRM_Core_ManagedEntities->reconcile()
#26 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Extension/Manager.php(252): CRM_Core_Invoke::rebuildMenuAndCaches(TRUE)
#27 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Extension/Manager.php(289): CRM_Extension_Manager->install((Array:1))
#28 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/api/v3/Extension.php(135): CRM_Extension_Manager->enable((Array:1))
#29 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_extension_enable((Array:2))
#30 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(169): Civi\API\Provider\MagicFunctionProvider->invoke((Array:9))
#31 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(100): Civi\API\Kernel->runRequest((Array:9))
#32 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/api/api.php(43): Civi\API\Kernel->runSafe("Extension", "enable", (Array:2))
#33 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Admin/Form/Extensions.php(195): civicrm_api3("Extension", "enable", (Array:2))
#34 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Form.php(447): CRM_Admin_Form_Extensions->postProcess()
#35 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/StateMachine.php(160): CRM_Core_Form->mainProcess()
#36 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/QuickForm/Action/Next.php(61): CRM_Core_StateMachine->perform(Object(CRM_Admin_Form_Extensions), "next", "Next")
#37 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/HTML/QuickForm/Controller.php(203): CRM_Core_QuickForm_Action_Next->perform(Object(CRM_Admin_Form_Extensions), "next")
#38 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/HTML/QuickForm/Page.php(103): HTML_QuickForm_Controller->handle(Object(CRM_Admin_Form_Extensions), "next")
#39 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Controller.php(351): HTML_QuickForm_Page->handle("next")
#40 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Page/Basic.php(398): CRM_Core_Controller->run()
#41 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Page/Basic.php(156): CRM_Core_Page_Basic->edit(32, NULL)
#42 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Admin/Page/Extensions.php(121): CRM_Core_Page_Basic->run()
#43 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(309): CRM_Admin_Page_Extensions->run((Array:3), NULL)
#44 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(84): CRM_Core_Invoke::runItem((Array:16))
#45 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke((Array:3))
#46 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm.php(1246): CRM_Core_Invoke::invoke((Array:3))
#47 /home/aquaparism/www/wp-includes/class-wp-hook.php(286): CiviCRM_For_WordPress->invoke("")
#48 /home/aquaparism/www/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters("", (Array:1))
#49 /home/aquaparism/www/wp-includes/plugin.php(453): WP_Hook->do_action((Array:1))
#50 /home/aquaparism/www/wp-admin/admin.php(224): do_action("toplevel_page_CiviCRM")
#51 {main}

A second error coming at the same time.

Apr 18 00:12:41  [info] $ManagedEntities_failed = Array
(
    [entity] => Dashboard
    [action] => create
    [params] => Array
        (
            [version] => 3
            [id] => 7
            [is_active] => 0
        )

    [result] => Array
        (
            [error_code] => constraint violation
            [sql] =>
                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, contact_id )
                  VALUES  ( 7, 2 ), ( 7, 9 ), ( 7, 10 ), ( 7, 12 ), ( 7, 13 ), ( 7, 19 ), ( 7, 20 ), ( 7, 21 ), ( 7, 22 ), ( 7, 31 ), ( 7, 36 ), ( 7, 39 ), ( 7, 76 ) [nativecode=1452 ** Cannot add or update a child row: a foreign key const
raint fails (`aquaparismcivi`.`civicrm_dashboard_contact`, CONSTRAINT `FK_civicrm_dashboard_contact_dashboard_id` FOREIGN KEY (`dashboard_id`) REFERENCES `civicrm_dashboard` (`id`) ON DELETE CASCADE)]
            [tip] => add debug=1 to your API call to have more info about the error
            [is_error] => 1
            [error_message] => DB Constraint Violation - domain_id should possibly be marked as mandatory for Dashboard,create API. If so, please raise a bug report.
            [debug_information] =>
                  INSERT INTO civicrm_dashboard_contact ( dashboard_id, contact_id )
                  VALUES  ( 7, 2 ), ( 7, 9 ), ( 7, 10 ), ( 7, 12 ), ( 7, 13 ), ( 7, 19 ), ( 7, 20 ), ( 7, 21 ), ( 7, 22 ), ( 7, 31 ), ( 7, 36 ), ( 7, 39 ), ( 7, 76 ) [nativecode=1452 ** Cannot add or update a child row: a foreign key const
raint fails (`aquaparismcivi`.`civicrm_dashboard_contact`, CONSTRAINT `FK_civicrm_dashboard_contact_dashboard_id` FOREIGN KEY (`dashboard_id`) REFERENCES `civicrm_dashboard` (`id`) ON DELETE CASCADE)]
        )

)

As suggested in various answers, I rerun the upgrade script with no success: my database is already upgraded.

Any idea from where it is coming and how I could solve it? This is a running database and I would like to not loose any data on it.

2

In the end I found the raison: on entry was missing in civicrm_dashboard. No entry with id 7. Since this entry was not their, the insertion in civicrm_dashboard_contact was failing for this entry as said in the logs.

It appear that I was missing the civizualize/contacts snippets. I just add the corresponding entry in civicrm_dashboard to solve the error.

Thanks to @kevin-cristiano for pointing me were to look for.

  • I found a site that was missing an entry as well. I wasn't sure how to find out which entry it was supposed to be, but as a temporary hackish fix, I created a new entry for the missing id (8 in this case) by duplicating an existing entry and leaving is_active set to 0. At least the fatal errors have stopped... 😬 – Laryn - CEDC.org Sep 21 '18 at 15:56
1

I had this error on a site where there was an entry in civicrm_dashboard that did not have a value in the domain_id column.

I backed up civicrm_dashboard and civicrm_dashboard_contact and then removed the row that had no domain_id from civicrm_dashboard and any corresponding rows from civicrm_dashboard_contact and I was fine.

Looking back on this, a better way would have been to first insert the proper domain_id in the civicrm_dashboard table.

Just be sure to backup the database and tables you are editing in case you hit a problem.

  • I have 8 lines in civicrm_dashboard and all of them have a domain_id equal to 1. So it does not seem to come from there. In the same time I have no line with id 7. I just need to know what to put for id 7. – T. Blein Apr 19 '18 at 8:21

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.