Answers.Body: <p>In step 5_15_alpha1 the field cacheKey must be renamed in cachekey. Is that done.</p>
  
  <p>Try to update the fieldname if it is cacheKey. 
  and then:
  CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entity_id2, entity_table, is_selected)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-27T10:18:06.807Z
Answers.Text: This was absolutely critical to the solution. Thanks!
Answers.UserDisplayName: Peter Evans
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-27T10:24:09.350Z
Answers.Text: After doing the update successfully I changed the name of the field back to cacheKey as it is referenced as such in the code 
  `./wp-content/plugins/civicrm/civicrm/CRM/Contact/Page/DedupeFind.php:    $this->assign('cacheKey', $cacheKeyString);`
  
  `./wp-content/plugins/civicrm/civicrm/CRM/Contact/Page/AJAX.php:    $cacheKeyString = CRM_Utils_Request::retrieve('cacheKey', 'Alphanumeric', $null, FALSE);`
  
  `./wp-content/plugins/civicrm/civicrm/CRM/Core/PrevNextCache/Sql.php:      ->where('pnc.cachekey = @cacheKey', ['cacheKey' => $cacheKey])`
Answers.UserDisplayName: Peter Evans
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-24T20:40:36.000Z
Answers.LastActivityDate: 2020-03-24T20:40:36.000Z
Answers.UserDisplayName: HanV
Answers.Body: <p>If the table is empty, try dropping and recreating it, i.e.</p>
  
  <p><code>SHOW CREATE TABLE civicrm_prevnext_cache;</code></p>
  
  <p>Then copy the output to the clipboard.</p>
  
  <p>Then <code>DROP TABLE civicrm_prevnext_cache;</code></p>
  
  <p>Then paste from the clipboard.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-27T10:21:00.210Z
Answers.Text: I did this too - this was kind of the partial implementation of the answer. In combination with the accepted answer the problem was solved. This alone was not enough. I had to s/cacheKey/cachekey/g in the create table statement.
Answers.UserDisplayName: Peter Evans
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-24T20:05:42.757Z
Answers.LastActivityDate: 2020-03-24T20:05:42.757Z
Answers.UserDisplayName: Demerit
Body: <p>Trying to carry out an upgrade of civicrm. It fails when trying to upgrade the database to 5.15.alpha1 due to "Incorrect key file for table" when trying to create an index called <code>index_all</code>. The table in question is not repairable. It is empty.</p>
  
  <p>Output of SHOW INDEXES</p>
  
  <pre><code>mysql&gt; show indexes from civicrm_prevnext_cache;
  +------------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  | Table                  | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
  +------------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  | civicrm_prevnext_cache |          0 | PRIMARY  |            1 | id          | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
  +------------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  1 row in set (0.00 sec)
  </code></pre>
  
  <p>I'd be grateful for any tips on how to fix this.</p>
  
  <p>The log file contains the following:</p>
  
  <pre><code>Mar 24 16:26:10  [info] Running task: Upgrade DB to 5.15.alpha1: SQL
  
  Mar 24 16:26:11  [info] Running task: Fix errant deferred revenue settings
  
  Mar 24 16:26:12  [info] Running task: Fix cache key column name in prev next cache
  
  Mar 24 16:26:12  [error] $Fatal Error Details = Array
  (
      [callback] =&gt; Array
          (
              [0] =&gt; CRM_Core_Error
              [1] =&gt; exceptionHandler
          )
  
      [code] =&gt; -1
      [message] =&gt; DB Error: unknown error
      [mode] =&gt; 16
      [debug_info] =&gt; CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entity_id2, entity_table, is_selected) [nativecode=1034 ** Incorrect key file for table 'civicrm_prevnext_cache'; try to repair it]
      [type] =&gt; DB_Error
      [user_info] =&gt; CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entity_id2, entity_table, is_selected) [nativecode=1034 ** Incorrect key file for table 'civicrm_prevnext_cache'; try to repair it]
      [to_string] =&gt; [db_error: message="DB Error: unknown error" code=-1 mode=callback callback=CRM_Core_Error::exceptionHandler prefix="" info="CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entity_id2, entity_table, is_selected) [nativecode=1034 ** Incorrect key file for table 'civicrm_prevnext_cache'; try to repair it]"]
  )
  
  
  Mar 24 16:26:12  [debug] $backTrace = #0 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php(915): CRM_Core_Error::backtrace("backTrace", TRUE)
  #1 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(922): CRM_Core_Error::exceptionHandler(Object(DB_Error))
  #2 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB.php(997): PEAR_Error-&gt;__construct("DB Error: unknown error", -1, 16, (Array:2), "CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #3 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(575): DB_Error-&gt;__construct(-1, 16, (Array:2), "CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #4 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(223): PEAR-&gt;_raiseError(Object(DB_mysqli), NULL, -1, 16, (Array:2), "CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...", "DB_Error", TRUE)
  #5 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1925): PEAR-&gt;__call("raiseError", (Array:7))
  #6 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/mysqli.php(935): DB_common-&gt;raiseError(-1, NULL, NULL, "CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...", "1034 ** Incorrect key file for table 'civicrm_prevnext_cache'; try to repair it")
  #7 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/mysqli.php(405): DB_mysqli-&gt;mysqliRaiseError()
  #8 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1231): DB_mysqli-&gt;simpleQuery("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #9 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/DataObject.php(2691): DB_common-&gt;query("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #10 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/DataObject.php(1829): DB_DataObject-&gt;_query("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #11 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/DAO.php(421): DB_DataObject-&gt;query("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #12 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/DAO.php(1420): CRM_Core_DAO-&gt;query("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...", TRUE)
  #13 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Upgrade/Incremental/php/FiveFifteen.php(74): CRM_Core_DAO::executeQuery("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #14 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Queue/Task.php(74): CRM_Upgrade_Incremental_php_FiveFifteen::fixCacheKeyColumnNamePrevNext(Object(CRM_Queue_TaskContext))
  #15 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Queue/Runner.php(202): CRM_Queue_Task-&gt;run(Object(CRM_Queue_TaskContext))
  #16 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Queue/Page/AJAX.php(36): CRM_Queue_Runner-&gt;runNext(TRUE)
  #17 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Queue/ErrorPolicy.php(90): CRM_Queue_Page_AJAX::{closure}()
  #18 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Queue/Page/AJAX.php(38): CRM_Queue_ErrorPolicy-&gt;call(Object(Closure))
  #19 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(234): CRM_Queue_Page_AJAX::runNext()
  #20 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(68): CRM_Core_Invoke::runItem((Array:13))
  #21 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(36): CRM_Core_Invoke::_invoke((Array:5))
  #22 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm.php(1449): CRM_Core_Invoke::invoke((Array:5))
  #23 /var/www/html/civcrm-test/civicrm/wp-includes/class-wp-hook.php(288): CiviCRM_For_WordPress-&gt;invoke("")
  #24 /var/www/html/civcrm-test/civicrm/wp-includes/class-wp-hook.php(312): WP_Hook-&gt;apply_filters("", (Array:1))
  #25 /var/www/html/civcrm-test/civicrm/wp-includes/plugin.php(478): WP_Hook-&gt;do_action((Array:1))
  #26 /var/www/html/civcrm-test/civicrm/wp-admin/admin.php(254): do_action("toplevel_page_CiviCRM")
  #27 {main}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-24T17:28:41.080Z
Comments.Text: From which version of Civi to what version of Civi are you tryong to upgrade?
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-27T10:25:55.237Z
Comments.Text: 5.11.0 --> 5.23.2
Comments.UserDisplayName: Peter Evans
Tags: <upgrade><database>
Title: Upgrade to 5.15.alpha1 fails due to "Incorrect key file for table" database error
ThreadText: # Upgrade to 5.15.alpha1 fails due to "Incorrect key file for table" database error
  
  (Asked by: username_0 on 2020-03-24)
  
  Trying to carry out an upgrade of civicrm. It fails when trying to upgrade the database to 5.15.alpha1 due to "Incorrect key file for table" when trying to create an index called index_all. The table in question is not repairable. It is empty.
  Output of SHOW INDEXES
  mysql> show indexes from civicrm_prevnext_cache;
  +------------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  | Table                  | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
  +------------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  | civicrm_prevnext_cache |          0 | PRIMARY  |            1 | id          | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
  +------------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  1 row in set (0.00 sec)
  
  I'd be grateful for any tips on how to fix this.
  The log file contains the following:
  Mar 24 16:26:10  [info] Running task: Upgrade DB to 5.15.alpha1: SQL
  
  Mar 24 16:26:11  [info] Running task: Fix errant deferred revenue settings
  
  Mar 24 16:26:12  [info] Running task: Fix cache key column name in prev next cache
  
  Mar 24 16:26:12  [error] $Fatal Error Details = Array
  (
      [callback] => Array
          (
              [0] => CRM_Core_Error
              [1] => exceptionHandler
          )
  
      [code] => -1
      [message] => DB Error: unknown error
      [mode] => 16
      [debug_info] => CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entity_id2, entity_table, is_selected) [nativecode=1034 ** Incorrect key file for table 'civicrm_prevnext_cache'; try to repair it]
      [type] => DB_Error
      [user_info] => CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entity_id2, entity_table, is_selected) [nativecode=1034 ** Incorrect key file for table 'civicrm_prevnext_cache'; try to repair it]
      [to_string] => [db_error: message="DB Error: unknown error" code=-1 mode=callback callback=CRM_Core_Error::exceptionHandler prefix="" info="CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entity_id2, entity_table, is_selected) [nativecode=1034 ** Incorrect key file for table 'civicrm_prevnext_cache'; try to repair it]"]
  )
  
  
  Mar 24 16:26:12  [debug] $backTrace = #0 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php(915): CRM_Core_Error::backtrace("backTrace", TRUE)
  #1 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(922): CRM_Core_Error::exceptionHandler(Object(DB_Error))
  #2 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB.php(997): PEAR_Error->__construct("DB Error: unknown error", -1, 16, (Array:2), "CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #3 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(575): DB_Error->__construct(-1, 16, (Array:2), "CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #4 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(223): PEAR->_raiseError(Object(DB_mysqli), NULL, -1, 16, (Array:2), "CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...", "DB_Error", TRUE)
  #5 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1925): PEAR->__call("raiseError", (Array:7))
  #6 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/mysqli.php(935): DB_common->raiseError(-1, NULL, NULL, "CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...", "1034 ** Incorrect key file for table 'civicrm_prevnext_cache'; try to repair it")
  #7 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/mysqli.php(405): DB_mysqli->mysqliRaiseError()
  #8 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1231): DB_mysqli->simpleQuery("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #9 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/DataObject.php(2691): DB_common->query("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #10 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/packages/DB/DataObject.php(1829): DB_DataObject->_query("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #11 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/DAO.php(421): DB_DataObject->query("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #12 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/DAO.php(1420): CRM_Core_DAO->query("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...", TRUE)
  #13 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Upgrade/Incremental/php/FiveFifteen.php(74): CRM_Core_DAO::executeQuery("CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entit...")
  #14 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Queue/Task.php(74): CRM_Upgrade_Incremental_php_FiveFifteen::fixCacheKeyColumnNamePrevNext(Object(CRM_Queue_TaskContext))
  #15 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Queue/Runner.php(202): CRM_Queue_Task->run(Object(CRM_Queue_TaskContext))
  #16 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Queue/Page/AJAX.php(36): CRM_Queue_Runner->runNext(TRUE)
  #17 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Queue/ErrorPolicy.php(90): CRM_Queue_Page_AJAX::{closure}()
  #18 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Queue/Page/AJAX.php(38): CRM_Queue_ErrorPolicy->call(Object(Closure))
  #19 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(234): CRM_Queue_Page_AJAX::runNext()
  #20 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(68): CRM_Core_Invoke::runItem((Array:13))
  #21 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(36): CRM_Core_Invoke::_invoke((Array:5))
  #22 /var/www/html/civcrm-test/civicrm/wp-content/plugins/civicrm/civicrm.php(1449): CRM_Core_Invoke::invoke((Array:5))
  #23 /var/www/html/civcrm-test/civicrm/wp-includes/class-wp-hook.php(288): CiviCRM_For_WordPress->invoke("")
  #24 /var/www/html/civcrm-test/civicrm/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters("", (Array:1))
  #25 /var/www/html/civcrm-test/civicrm/wp-includes/plugin.php(478): WP_Hook->do_action((Array:1))
  #26 /var/www/html/civcrm-test/civicrm/wp-admin/admin.php(254): do_action("toplevel_page_CiviCRM")
  #27 {main}
  
  **Tags:** upgrade, database
  
  > **Comments:**
  > **username_1**: From which version of Civi to what version of Civi are you tryong to upgrade?  
  > **username_0**: 5.11.0 --> 5.23.2  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-03-24. Score: 2 | Accepted answer
  
  In step 5\_15\_alpha1 the field cacheKey must be renamed in cachekey. Is that done.
  
  Try to update the fieldname if it is cacheKey.
  and then:
  CREATE INDEX index\_all ON civicrm\_prevnext\_cache (cachekey, entity\_id1, entity\_id2, entity\_table, is\_selected)
  
  > **Comments:**
  > **username_0**: This was absolutely critical to the solution. Thanks!  
  > **username_0**: After doing the update successfully I changed the name of the field back to cacheKey as it is referenced as such in the code  `./wp-content/plugins/civicrm/civicrm/CRM/Contact/Page/DedupeFind.php:    $this->assign('cacheKey', $cacheKeyString);`  `./wp-content/plugins/civicrm/civicrm/CRM/Contact/Page/AJAX.php:    $cacheKeyString = CRM_Utils_Request::retrieve('cacheKey', 'Alphanumeric', $null, FALSE);`  `./wp-content/plugins/civicrm/civicrm/CRM/Core/PrevNextCache/Sql.php:      ->where('pnc.cachekey = @cacheKey', ['cacheKey' => $cacheKey])`  
  
  ---
  
  ### Answer by username_3 on 2020-03-24. Score: 2
  
  If the table is empty, try dropping and recreating it, i.e.
  
  `SHOW CREATE TABLE civicrm_prevnext_cache;`
  
  Then copy the output to the clipboard.
  
  Then `DROP TABLE civicrm_prevnext_cache;`
  
  Then paste from the clipboard.
  
  > **Comments:**
  > **username_0**: I did this too - this was kind of the partial implementation of the answer. In combination with the accepted answer the problem was solved. This alone was not enough. I had to s/cacheKey/cachekey/g in the create table statement.  
  
  ---
  
  