Answers.Body: <p>In the end I found the raison: on entry was missing in <code>civicrm_dashboard</code>. No entry with <code>id</code> <code>7</code>. Since this entry was not their, the insertion in <code>civicrm_dashboard_contact</code> was failing for this entry as said in the logs.</p>
  
  <p>It appear that I was missing the <code>civizualize/contacts</code> snippets. I just add the corresponding entry in <code>civicrm_dashboard</code> to solve the error.</p>
  
  <p>Thanks to @kevin-cristiano for pointing me were to look for.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-21T15:56:28.223Z
Answers.Text: 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... 
Answers.UserDisplayName: Laryn
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T09:12:24.943Z
Answers.LastActivityDate: 2018-04-19T09:12:24.943Z
Answers.UserDisplayName: T. Blein
Answers.Body: <p>I had this error on a site where there was an entry in <code>civicrm_dashboard</code> that did not have a value in the <code>domain_id</code> column.   </p>
  
  <p>I backed up <code>civicrm_dashboard</code> and <code>civicrm_dashboard_contact</code> and then removed the row that had no domain_id from <code>civicrm_dashboard</code> and any corresponding rows from <code>civicrm_dashboard_contact</code> and I was fine.</p>
  
  <p>Looking back on this, a better way would have been to first insert the proper domain_id in the <code>civicrm_dashboard</code> table.   </p>
  
  <p>Just be sure to backup the database and tables you are editing in case you hit a problem.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T08:21:22.777Z
Answers.Text: 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`.
Answers.UserDisplayName: T. Blein
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-18T00:06:55.187Z
Answers.LastActivityDate: 2018-04-18T00:06:55.187Z
Answers.UserDisplayName: Kevin Cristiano
Body: <p>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.</p>
  
  <p>This is an error that is present since some month and therefore some releases (I do not remember when exactly).</p>
  
  <p>The detailed error message:</p>
  
  <pre><code>Apr 18 00:12:41  [info] $Fatal Error Details = Array
  (
      [callback] =&gt; Array
          (
              [0] =&gt; CRM_Core_Error
              [1] =&gt; exceptionHandler
          )
  
      [code] =&gt; -3
      [message] =&gt; DB Error: constraint violation
      [mode] =&gt; 16
      [debug_info] =&gt;
                    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] =&gt; DB_Error
      [user_info] =&gt;
                    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] =&gt; [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)]"]
  )
  </code></pre>
  
  <p>The trace</p>
  
  <pre><code>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-&gt;__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-&gt;__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-&gt;_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-&gt;__call("raiseError", (Array:7))
  #6 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/DB/mysqli.php(933): DB_common-&gt;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-&gt;mysqliRaiseError()
  #8 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1216): DB_mysqli-&gt;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-&gt;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-&gt;_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-&gt;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-&gt;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-&gt;invoke((Array:9))
  #20 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(100): Civi\API\Kernel-&gt;runRequest((Array:9))
  #21 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/api/api.php(23): Civi\API\Kernel-&gt;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-&gt;disableEntity(Object(CRM_Core_DAO_Managed))
  #24 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/ManagedEntities.php(123): CRM_Core_ManagedEntities-&gt;reconcileDisabledModules()
  #25 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(395): CRM_Core_ManagedEntities-&gt;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-&gt;install((Array:1))
  #28 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/api/v3/Extension.php(135): CRM_Extension_Manager-&gt;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-&gt;invoke((Array:9))
  #31 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(100): Civi\API\Kernel-&gt;runRequest((Array:9))
  #32 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/api/api.php(43): Civi\API\Kernel-&gt;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-&gt;postProcess()
  #35 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/StateMachine.php(160): CRM_Core_Form-&gt;mainProcess()
  #36 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/QuickForm/Action/Next.php(61): CRM_Core_StateMachine-&gt;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-&gt;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-&gt;handle(Object(CRM_Admin_Form_Extensions), "next")
  #39 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Controller.php(351): HTML_QuickForm_Page-&gt;handle("next")
  #40 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Page/Basic.php(398): CRM_Core_Controller-&gt;run()
  #41 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Page/Basic.php(156): CRM_Core_Page_Basic-&gt;edit(32, NULL)
  #42 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Admin/Page/Extensions.php(121): CRM_Core_Page_Basic-&gt;run()
  #43 /home/aquaparism/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(309): CRM_Admin_Page_Extensions-&gt;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-&gt;invoke("")
  #48 /home/aquaparism/www/wp-includes/class-wp-hook.php(310): WP_Hook-&gt;apply_filters("", (Array:1))
  #49 /home/aquaparism/www/wp-includes/plugin.php(453): WP_Hook-&gt;do_action((Array:1))
  #50 /home/aquaparism/www/wp-admin/admin.php(224): do_action("toplevel_page_CiviCRM")
  #51 {main}
  </code></pre>
  
  <p>A second error coming at the same time.</p>
  
  <pre><code>Apr 18 00:12:41  [info] $ManagedEntities_failed = Array
  (
      [entity] =&gt; Dashboard
      [action] =&gt; create
      [params] =&gt; Array
          (
              [version] =&gt; 3
              [id] =&gt; 7
              [is_active] =&gt; 0
          )
  
      [result] =&gt; Array
          (
              [error_code] =&gt; constraint violation
              [sql] =&gt;
                    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] =&gt; add debug=1 to your API call to have more info about the error
              [is_error] =&gt; 1
              [error_message] =&gt; DB Constraint Violation - domain_id should possibly be marked as mandatory for Dashboard,create API. If so, please raise a bug report.
              [debug_information] =&gt;
                    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)]
          )
  
  )
  </code></pre>
  
  <p>As suggested in various answers, I rerun the upgrade script with no success: my database is already upgraded.</p>
  
  <p>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.</p>
  
Tags: <wordpress><database>
Title: API error: DB Constraint Violation - domain_id should possibly be marked as mandatory for Dashboard,create API. If so, please raise a bug report
ThreadText: # API error: DB Constraint Violation - domain_id should possibly be marked as mandatory for Dashboard,create API. If so, please raise a bug report
  
  (Asked by: username_0 on 2018-04-17)
  
  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.
  
  **Tags:** wordpress, database
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2018-04-19. Score: 2 | Accepted answer
  
  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 @username_2-username_2 for pointing me were to look for.
  
  > **Comments:**
  > **username_1**: 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...   
  
  ---
  
  ### Answer by username_2 on 2018-04-18. Score: 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.
  
  > **Comments:**
  > **username_0**: 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`.  
  
  ---
  
  