On running an upgrade to 5.47.1 I get the following

[Error: Finish core DB updates 5.47.1] Exception: "API error: DB Error: constraint violation on ReportTemplate.create"

Partial stacktrace

#0 [civicrm-root]/CRM/Core/ManagedEntities.php(375): CRM_Core_ManagedEntities->onApiError("ReportTemplate", "create", (Array:8), (Array:6))
#1 [civicrm-root]/CRM/Core/ManagedEntities.php(187): CRM_Core_ManagedEntities->updateExistingEntity(Object(CRM_Core_DAO_Managed), (Array:10))
#2 [civicrm-root]/CRM/Core/ManagedEntities.php(167): CRM_Core_ManagedEntities->reconcileEnabledModule("nz.co.fuzion.extendedreport")
#3 [civicrm-root]/CRM/Core/ManagedEntities.php(128): CRM_Core_ManagedEntities->reconcileEnabledModules()
#4 [civicrm-root]/CRM/Core/Invoke.php(413): CRM_Core_ManagedEntities->reconcile()
#5 [civicrm-root]/CRM/Upgrade/Form.php(818): CRM_Core_Invoke::rebuildMenuAndCaches(FALSE, TRUE)
#6 [civicrm-root]/CRM/Queue/Task.php(73): CRM_Upgrade_Form::doCoreFinish(Object(CRM_Queue_TaskContext), "5.47.1", "5.47.1", "5.47.1", "/tmp/civicrm-post-upgradeRgUuuC")
#7 [civicrm-root]/CRM/Queue/Runner.php(215): CRM_Queue_Task->run(Object(CRM_Queue_TaskContext))
#8 [civicrm-root]/CRM/Queue/Page/AJAX.php(36): CRM_Queue_Runner->runNext(TRUE)
#9 [civicrm-root]/CRM/Queue/ErrorPolicy.php(89): CRM_Queue_Page_AJAX::{closure}()
#10 [civicrm-root]/CRM/Queue/Page/AJAX.php(38): CRM_Queue_ErrorPolicy->call(Object(Closure))
#11 [civicrm-root]/CRM/Core/Invoke.php(285): CRM_Queue_Page_AJAX::runNext()
#12 [civicrm-root]/CRM/Core/Invoke.php(69): CRM_Core_Invoke::runItem((Array:13))
#13 [civicrm-root]/CRM/Core/Invoke.php(36): CRM_Core_Invoke::_invoke((Array:5))
#14 [civicrm-root]/civicrm/src/Civicrm.php(88): CRM_Core_Invoke::invoke((Array:5))
#15 /civicrm/src/Controller/CivicrmController.php(80): Drupal\civicrm\Civicrm->invoke((Array:5))
#16 [internal function](): Drupal\civicrm\Controller\CivicrmController->main((Array:5), "queue:ajax:runNext")
  • Thanks. I was planning on posting about this over the weekend. Now I have some solutions to try on the site I'm working to upgrade. Mar 11, 2022 at 15:34

2 Answers 2


The problem here was the Extension Extended Reports - however it's possible that you have a different extension causing the problem.

In 5.47.0 CiviGrant component was transferred to an extension. You need to upgrade to at least the 5.12.1 version of CiviCRM Extended reports.

If you have hit this you should be able to finish the upgrade tasks manually:

You will need to Flush Caches Rebuild all triggers (If you haven't turned them off for the upgrade) and force a rebuild of the CiviCRM Asset Cache

To do via the UI you will want to clear caches and toggle logging on and off - If you didn't turn it off for the upgrade.

The PHP to do this if you prefer can be found at https://github.com/civicrm/civicrm-core/blob/1754e1752eb8e516ec846a438005f6fcb55be247/CRM/Upgrade/Form.php#L818

where you want to run everything until the end of that method.

  • 2
    thanks for this great answer. What I did that was worked was 1. Go to /civicrm/admin/extensions?reset=1&action=browse and upgraded Extended Reports. 2. I used cv php:eval to run line 818. 3. I ran cv flush 4. I put lines 824-828 in a script and ran that with cv php:script. You might be able to just use all of the lines between 818-828 in one script and save some steps. Hope this helps. -Josh
    – Josh
    Apr 11, 2022 at 4:46
  • Thanks, How can I tell if it ran successfully? I rant cv php:script path/to/script something ran but I did not get any output or errors, So I assume it went through successfully.
    – Netzih
    Jul 4, 2022 at 17:27

There few other alternate approaches to proceed with Civi 5.47 upgrade if you have an Extended report extension enabled

  1. Upgrade CiviCRM to 5.46.2 -> Upgrade Extended report to 5.13 -> Upgrade CiviCRM to 5.47.1

  2. Upgrade Extended report to 5.13 -> Upgrade CiviCRM to 5.47.1

  3. Comment the line 127 in CRM/Upgrade/Incremental/php/FiveFortySeven.php -> Upgrade CiviCRM to 5.47.1 -> Upgrade Extended report to 5.13

  • Option 3 - Won't you want to follow up afterwards and execute that sql to remove it out of the component list? Mar 13, 2022 at 19:55
  • yes but that shouldn't cause any problem if stays in Mar 13, 2022 at 23:14
  • running into the same errors when update extensions along with 5.30.3 upgrade. A real mess so far as it is not clear which extensions have the problems. API error: DB Error: constraint violation on ReportTemplate.create
    – Dave T
    Jun 24, 2022 at 18:46
  • same error upgrading Mosaico before Civi upgrade
    – Dave T
    Jun 24, 2022 at 19:46
  • You need upgrade extended report extension Jun 26, 2022 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.