Answers.Body: <p>This looks to be a problem with an entity_type row of PaymentProcessorType in the civicrm_managed table.</p>
  
  <p>To show the offending row:
  select * from civicrm_managed where entity_type='PaymentProcessorType';</p>
  
  <p>Remove the offending row:
  delete from civicrm_managed where entity_type='PaymentProcessorType';</p>
  
  <p>Then re-run the upgrade.</p>
  
  <p>After the upgrade was re-run, I had to re-add the offending row for the 'ExtenededReports' extension added reports to show up.  Installing the 'CiviCRM Log Viewer' extension without this line also gave the same error of database record already exists.  In this instance, this is dealing with a record from the extension 'Authorize.net eCheck.Net'.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-20T22:36:29.943Z
Answers.Text: Can confirm this solution works.
  
  See CiviCRM bug report, https://lab.civicrm.org/dev/core/issues/1498
Answers.UserDisplayName: Justin Freeman - Agileware
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-20T21:48:22.120Z
Answers.LastActivityDate: 2020-01-02T17:14:14.653Z
Answers.LastEditDate: 2020-01-02T17:14:14.653Z
Answers.UserDisplayName: G H
Body: <p>In upgrading to 5.20+ an error occured while running the database Case upgrade scripts.  </p>
  
  <p>Deletion Error
  There is a Payment Processor associated with selected Payment Processor type, hence it can not be deleted.</p>
  
  <pre><code>CiviCRM_API3_Exception: "API error: Could not delete payment processor type"
  
  #0 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Upgrade/Incremental/php/FiveTwenty.php(370): civicrm_api3("CaseType", "create", (Array:9))
  #1 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Upgrade/Incremental/php/FiveTwenty.php(289): CRM_Upgrade_Incremental_php_FiveTwenty::_processCaseTypeLabelName(FALSE, "7")
  #2 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Upgrade/Incremental/php/FiveTwenty.php(265): CRM_Upgrade_Incremental_php_FiveTwenty::_changeCaseTypeLabelToName(FALSE)
  #3 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Queue/Task.php(88): CRM_Upgrade_Incremental_php_FiveTwenty::changeCaseTypeLabelToName(Object(CRM_Queue_TaskContext))
  #4 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Queue/Runner.php(217): CRM_Queue_Task-&gt;run(Object(CRM_Queue_TaskContext))
  #5 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Queue/Page/AJAX.php(52): CRM_Queue_Runner-&gt;runNext(TRUE)
  #6 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Queue/ErrorPolicy.php(106): CRM_Queue_Page_AJAX::{closure}()
  #7 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Queue/Page/AJAX.php(54): CRM_Queue_ErrorPolicy-&gt;call(Object(Closure))
  #8 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(250): CRM_Queue_Page_AJAX::runNext()
  #9 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(84): CRM_Core_Invoke::runItem((Array:13))
  #10 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke((Array:5))
  #11 /dir/wp/wp-content/plugins/civicrm/civicrm.php(1465): CRM_Core_Invoke::invoke((Array:5))
  #12 /dir/wp/wp-includes/class-wp-hook.php(288): CiviCRM_For_WordPress-&gt;invoke("")
  #13 /dir/wp/wp-includes/class-wp-hook.php(312): WP_Hook-&gt;apply_filters("", (Array:1))
  #14 /dir/wp/wp-includes/plugin.php(478): WP_Hook-&gt;do_action((Array:1))
  #15 /dir/wp/wp-admin/admin.php(254): do_action("toplevel_page_CiviCRM")
  #16 {main}
  </code></pre>
  
Tags: <upgrade><database><failure>
Title: Upgrade fails with CiviCRM_API3_Exception: "API error: Could not delete payment processor type"
ThreadText: # Upgrade fails with CiviCRM_API3_Exception: "API error: Could not delete payment processor type"
  
  (Asked by: username_0 on 2019-12-20)
  
  In upgrading to 5.20+ an error occured while running the database Case upgrade scripts.
  
  Deletion Error
  There is a Payment Processor associated with selected Payment Processor type, hence it can not be deleted.
  
  ```
  CiviCRM_API3_Exception: "API error: Could not delete payment processor type"
  
  #0 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Upgrade/Incremental/php/FiveTwenty.php(370): civicrm_api3("CaseType", "create", (Array:9))
  #1 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Upgrade/Incremental/php/FiveTwenty.php(289): CRM_Upgrade_Incremental_php_FiveTwenty::_processCaseTypeLabelName(FALSE, "7")
  #2 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Upgrade/Incremental/php/FiveTwenty.php(265): CRM_Upgrade_Incremental_php_FiveTwenty::_changeCaseTypeLabelToName(FALSE)
  #3 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Queue/Task.php(88): CRM_Upgrade_Incremental_php_FiveTwenty::changeCaseTypeLabelToName(Object(CRM_Queue_TaskContext))
  #4 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Queue/Runner.php(217): CRM_Queue_Task->run(Object(CRM_Queue_TaskContext))
  #5 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Queue/Page/AJAX.php(52): CRM_Queue_Runner->runNext(TRUE)
  #6 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Queue/ErrorPolicy.php(106): CRM_Queue_Page_AJAX::{closure}()
  #7 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Queue/Page/AJAX.php(54): CRM_Queue_ErrorPolicy->call(Object(Closure))
  #8 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(250): CRM_Queue_Page_AJAX::runNext()
  #9 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(84): CRM_Core_Invoke::runItem((Array:13))
  #10 /dir/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke((Array:5))
  #11 /dir/wp/wp-content/plugins/civicrm/civicrm.php(1465): CRM_Core_Invoke::invoke((Array:5))
  #12 /dir/wp/wp-includes/class-wp-hook.php(288): CiviCRM_For_WordPress->invoke("")
  #13 /dir/wp/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters("", (Array:1))
  #14 /dir/wp/wp-includes/plugin.php(478): WP_Hook->do_action((Array:1))
  #15 /dir/wp/wp-admin/admin.php(254): do_action("toplevel_page_CiviCRM")
  #16 {main}
  
  ```
  
  **Tags:** upgrade, database, failure
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-12-20. Score: 7 | Accepted answer
  
  This looks to be a problem with an entity\_type row of PaymentProcessorType in the civicrm\_managed table.
  
  To show the offending row:
  select \* from civicrm\_managed where entity\_type='PaymentProcessorType';
  
  Remove the offending row:
  delete from civicrm\_managed where entity\_type='PaymentProcessorType';
  
  Then re-run the upgrade.
  
  After the upgrade was re-run, I had to re-add the offending row for the 'ExtenededReports' extension added reports to show up. Installing the 'CiviCRM Log Viewer' extension without this line also gave the same error of database record already exists. In this instance, this is dealing with a record from the extension 'Authorize.net eCheck.Net'.
  
  > **Comments:**
  > **username_1**: Can confirm this solution works.  See CiviCRM bug report, https://lab.civicrm.org/dev/core/issues/1498  
  
  ---
  
  