Answers.Body: <p>If there are indices problem, you can get false indices displayed on <code>Administer -&gt; Administration Console -&gt; System Status</code> page. </p>
  
  <p>It will list the wrong indices in your table with the <code>Update Indices</code> button to rebuild them. </p>
  
  <p><a href="https://i.sstatic.net/mqOw6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mqOw6.png" alt="enter image description here"></a></p>
  
  <p>The above button tries to delete the listed false indices and recreate them in the correct order. If for some reason the <code>Update Indices</code> is unable to clear the message, you can manually delete the indices from the <code>Table Name</code> shown in the above screen and then create them using the same button.</p>
  
  <p>Note that you can only see this message and button if your civi version is &lt;= 4.7.29. From 4.7.30, this message is hidden via <a href="https://issues.civicrm.org/jira/browse/CRM-21298" rel="nofollow noreferrer"><code>CRM-21298</code></a>.</p>
  
  <p>So, on version >= 4.7.30, as this UI is not present, you can try rebuilding them using the api via API explorer from <code>Support -&gt; Developer -&gt; API Explorer</code> with </p>
  
  <p>Entity = <code>System</code> and Action = <code>updateindexes</code> (present on all versions). </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-08T14:28:40.010Z
Answers.Text: Ok, thanks for this.  I'm running 4.7.29 so I ran the API updateindexes.  Unfortunately I continue to get the error noted in the original issue.  It can't seem to evaluate between existing indexes and required indexes?  Where does it get the list of required indexes for the comparison?  Perhaps there is an issue there.
Answers.UserDisplayName: Norm Dressler
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-08T21:16:07.117Z
Answers.Text: Interesting - I migrated a copy of production to a local VM running LAMP and I don't seem to get that error there!
Answers.UserDisplayName: Norm Dressler
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-09T04:38:49.907Z
Answers.Text: Do you see the screenshot on the "System Status" page? i.e, any false indices showing up there? If not, try rebuilding the menu using `http://<yourdomain>/civicrm/menu/rebuild?reset=1` in the URL and clearing drupal cache.
Answers.UserDisplayName: jitendra - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-08T03:05:55.667Z
Answers.LastActivityDate: 2018-01-08T05:02:20.687Z
Answers.LastEditDate: 2018-01-08T05:02:20.687Z
Answers.UserDisplayName: jitendra - fuzion
Answers.Body: <p>I have seen same issue before and for same index 'UI_case_contact_id'. The reason is 'update indices' script tries to recreate the index which already exists so we need to delete the existing 'UI_case_contact_id' index and let the script create from scratch but before that you would need to create a temporary foreign key which will be deleted at the end of all steps. Follow the following steps to fix it:</p>
  <ol>
  <li><p>Create temporary foreign key by SQL command:</p>
  <p><code>CREATE UNIQUE INDEX my_temp_key ON civicrm_case_contact (case_id, contact_id);</code></p>
  </li>
  <li><p>Delete index UI_case_contact_id:</p>
  <p><code>DROP INDEX UI_case_contact_id ON civicrm_case_contact;</code></p>
  </li>
  <li><p>Run the 'Update indices' script</p>
  </li>
  <li><p>Delete temporary key that was created:</p>
  <p><code>DROP INDEX my_temp_key ON civicrm_case_contact;</code></p>
  </li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-08T19:48:44.957Z
Answers.Text: It's not me who is missing or have an issue with that index - its the replier to my original post.  Mine isn't showing any missing indexes, just the error.
Answers.UserDisplayName: Norm Dressler
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-08T18:17:35.253Z
Answers.LastActivityDate: 2018-01-08T18:17:35.253Z
Answers.LastEditDate: 2020-06-17T09:00:50.810Z
Answers.UserDisplayName: Hassan Farooq
Body: <p>I am getting random errors when I first log into Civicrm on Wordpress.  It seems to be related to the check of existing indexes versus required indexes.</p>
  
  <p>Warning: Invalid argument supplied for foreach() in /home/sporti62/public_html/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/SchemaHandler.php on line 750</p>
  
  <p>Is there a tool where I can have the indexes checked and possibly rebuilt?</p>
  
  <p>Norm</p>
  
Tags: <database>
Title: Database Schema check/fix
ThreadText: # Database Schema check/fix
  
  (Asked by: username_0 on 2018-01-07)
  
  I am getting random errors when I first log into Civicrm on Wordpress. It seems to be related to the check of existing indexes versus required indexes.
  
  Warning: Invalid argument supplied for foreach() in /home/sporti62/public\_html/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/SchemaHandler.php on line 750
  
  Is there a tool where I can have the indexes checked and possibly rebuilt?
  
  username_0
  
  **Tags:** database
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-01-08. Score: 2
  
  If there are indices problem, you can get false indices displayed on `Administer -> Administration Console -> System Status` page.
  
  It will list the wrong indices in your table with the `Update Indices` button to rebuild them.
  
  [![enter image description here](https://i.sstatic.net/mqOw6.png)](https://i.sstatic.net/mqOw6.png)
  
  The above button tries to delete the listed false indices and recreate them in the correct order. If for some reason the `Update Indices` is unable to clear the message, you can manually delete the indices from the `Table Name` shown in the above screen and then create them using the same button.
  
  Note that you can only see this message and button if your civi version is <= 4.7.29. From 4.7.30, this message is hidden via [`CRM-21298`](https://issues.civicrm.org/jira/browse/CRM-21298).
  
  So, on version >= 4.7.30, as this UI is not present, you can try rebuilding them using the api via API explorer from `Support -> Developer -> API Explorer` with
  
  Entity = `System` and Action = `updateindexes` (present on all versions).
  
  > **Comments:**
  > **username_0**: Ok, thanks for this.  I'm running 4.7.29 so I ran the API updateindexes.  Unfortunately I continue to get the error noted in the original issue.  It can't seem to evaluate between existing indexes and required indexes?  Where does it get the list of required indexes for the comparison?  Perhaps there is an issue there.  
  > **username_0**: Interesting - I migrated a copy of production to a local VM running LAMP and I don't seem to get that error there!  
  > **username_1**: Do you see the screenshot on the "System Status" page? i.e, any false indices showing up there? If not, try rebuilding the menu using `http://<yourdomain>/civicrm/menu/rebuild?reset=1` in the URL and clearing drupal cache.  
  
  ---
  
  ### Answer by username_2 on 2018-01-08. Score: 0
  
  I have seen same issue before and for same index 'UI\_case\_contact\_id'. The reason is 'update indices' script tries to recreate the index which already exists so we need to delete the existing 'UI\_case\_contact\_id' index and let the script create from scratch but before that you would need to create a temporary foreign key which will be deleted at the end of all steps. Follow the following steps to fix it:
  
  1. Create temporary foreign key by SQL command:
  
     `CREATE UNIQUE INDEX my_temp_key ON civicrm_case_contact (case_id, contact_id);`
  2. Delete index UI\_case\_contact\_id:
  
     `DROP INDEX UI_case_contact_id ON civicrm_case_contact;`
  3. Run the 'Update indices' script
  4. Delete temporary key that was created:
  
     `DROP INDEX my_temp_key ON civicrm_case_contact;`
  
  > **Comments:**
  > **username_0**: It's not me who is missing or have an issue with that index - its the replier to my original post.  Mine isn't showing any missing indexes, just the error.  
  
  ---
  
  