Answers.Body: <p>You can apply <a href="https://github.com/civicrm/civicrm-core/pull/10566" rel="nofollow noreferrer">this PR</a> - and reload System status page. This will let you know in advance which indices are already present in DB and would result in DB error on hitting Update Indices button. So what need to be done is -</p>
  
  <ul>
  <li>Apply this PR.</li>
  <li>Reload System status page.</li>
  <li>Some duplicate indices would be shown above <code>Update Indices</code> button including a message of what needs to be done.</li>
  <li>Delete indices manually from the DB (which are listed on above step). </li>
  <li>Execute <code>Update Indices</code> button.</li>
  </ul>
  
  <p>Update: just saw the error again - So the error say you have two rows which contain the same values for (entity_id, entity_table, account_relationship) as 5, civicrm_financial_type and 3 respectively. This should not be there as this group of fields are meant to be unique. To remove this error, you can -</p>
  
  <ul>
  <li>Open <code>civicrm_entity_financial_account</code> table.</li>
  <li>Search for rows that match <code>entity_id = 5</code>, <code>entity_table = civicrm_financial_type</code> and <code>account_relationship = 3</code>. You'll get two rows(This table should allow only one after indexing), delete one of them and re-execute <code>Update Indices</code> button. This is not provided by core as of now, so we have to do this manually.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-08T12:23:46.573Z
Answers.Text: I applied the PR suggested, and then Civi listed one index that I removed which wasn't the one listed above. Then reran the update and got exactly the same error as above. So no further forward.  Suggestions?  Shouldn't Civi be able to cope with problems like this? Is there a reason this has to be sorted manually?
Answers.UserDisplayName: Andy Clark
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-08T13:05:07.540Z
Answers.Text: Updated the answer.
Answers.UserDisplayName: jitendra - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-16T18:57:55.237Z
Answers.Text: Applied the PR. The System Status now says there is an issue with civicrm_case_contact.case_id and .contact_id, but it won't let me drop these two because they're needed in a foreign key constraint. 
  
  Tried to remove the foreign key (ALTER TABLE civicrm_case_contact DROP FOREIGN KEY civicrm_case_contact.case_id ;) but then get the message "Can't DROP 'case_id'; check that column/key exists".
  
  I have tried the 'Update indices' button but it just reloads the System Status page with no changes. Any ideas?
Answers.UserDisplayName: Rose Lanigan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-27T11:43:58.277Z
Answers.Text: @RoseLanigan this answer might be helpful https://civicrm.stackexchange.com/questions/18487/how-to-find-and-or-fix-missing-indices/19424#comment22161_19424
Answers.UserDisplayName: William Mortada
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-31T20:55:28.223Z
Answers.Text: @WilliamMortada perfect, thank you (and thanks to Artful Robot!)
Answers.UserDisplayName: Rose Lanigan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-08T11:14:52.430Z
Answers.LastActivityDate: 2017-07-08T13:01:24.123Z
Answers.LastEditDate: 2017-07-08T13:01:24.123Z
Answers.UserDisplayName: jitendra - fuzion
Body: <p>Upgraded from 4.7.17 to 4.7.21 and got the following message that I don't know how to fix. I don't have drush and the other answers to this problem don't include this index or don't fix this particular problem.  I tried "ALTER TABLE civicrm_financial_type DROP INDEX index_entity_id_entity_table_account_relationship" but MySQL can't do it and says 'check that column/key exists'.  Also tried 'ALTER TABLE civicrm_entity_financial_account  DROP INDEX index_entity_id_entity_table_account_relationship' with the same result</p>
  
  <blockquote>
    <p><strong>Operation failed: Update Indices DB Error: already exists Debug information: CREATE UNIQUE INDEX
    index_entity_id_entity_table_account_relationship ON
    civicrm_entity_financial_account (entity_id, entity_table,
    account_relationship) [nativecode=1062 ** Duplicate entry
    '5-civicrm_financial_type-3' for key
    'index_entity_id_entity_table_account_relationship']</strong></p>
  </blockquote>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-14T15:21:12.850Z
Comments.Text: This issues appears to have re-surfaced. Just upgrade a Wordpress installation from 4.7.14 to 4.7.22 and got the same error. [![enter image description here](https://i.sstatic.net/UdmzT.jpg)](https://i.sstatic.net/UdmzT.jpg)
Comments.UserDisplayName: Len Inkster
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-14T20:48:26.387Z
Comments.Text: Hi Len. This isn't an Answer so should have been added as a Comment but perhaps you don't have enough 'credit' to make comments. I don't think the Answer by Jitendra implied this has been fixed in 4.7.22, rather he has explained how you can sort this out by removing the Index in question. hope that helps
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-27T11:47:22.697Z
Comments.Text: Possible duplicate of https://civicrm.stackexchange.com/questions/18487/how-to-find-and-or-fix-missing-indices ?
Comments.UserDisplayName: William Mortada
Tags: <database><4.7><upgrade>
Title: How can I fix this problem with duplicate index in 4.7.21?
ThreadText: # How can I fix this problem with duplicate index in 4.7.21?
  
  (Asked by: username_0 on 2017-07-08)
  
  Upgraded from 4.7.17 to 4.7.21 and got the following message that I don't know how to fix. I don't have drush and the other answers to this problem don't include this index or don't fix this particular problem. I tried "ALTER TABLE civicrm\_financial\_type DROP INDEX index\_entity\_id\_entity\_table\_account\_relationship" but MySQL can't do it and says 'check that column/key exists'. Also tried 'ALTER TABLE civicrm\_entity\_financial\_account DROP INDEX index\_entity\_id\_entity\_table\_account\_relationship' with the same result
  
  > **Operation failed: Update Indices DB Error: already exists Debug information: CREATE UNIQUE INDEX
  > index\_entity\_id\_entity\_table\_account\_relationship ON
  > civicrm\_entity\_financial\_account (entity\_id, entity\_table,
  > account\_relationship) [nativecode=1062 \*\* Duplicate entry
  > '5-civicrm\_financial\_type-3' for key
  > 'index\_entity\_id\_entity\_table\_account\_relationship']**
  
  **Tags:** database, 4.7, upgrade
  
  > **Comments:**
  > **username_1**: This issues appears to have re-surfaced. Just upgrade a Wordpress installation from 4.7.14 to 4.7.22 and got the same error. [![enter image description here](https://i.sstatic.net/UdmzT.jpg)](https://i.sstatic.net/UdmzT.jpg)  
  > **username_2**: Hi Len. This isn't an Answer so should have been added as a Comment but perhaps you don't have enough 'credit' to make comments. I don't think the Answer by username_4 implied this has been fixed in 4.7.22, rather he has explained how you can sort this out by removing the Index in question. hope that helps  
  > **username_3**: Possible duplicate of https://civicrm.stackexchange.com/questions/18487/how-to-find-and-or-fix-missing-indices ?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_4 on 2017-07-08. Score: 4
  
  You can apply [this PR](https://github.com/civicrm/civicrm-core/pull/10566) - and reload System status page. This will let you know in advance which indices are already present in DB and would result in DB error on hitting Update Indices button. So what need to be done is -
  
  * Apply this PR.
  * Reload System status page.
  * Some duplicate indices would be shown above `Update Indices` button including a message of what needs to be done.
  * Delete indices manually from the DB (which are listed on above step).
  * Execute `Update Indices` button.
  
  Update: just saw the error again - So the error say you have two rows which contain the same values for (entity\_id, entity\_table, account\_relationship) as 5, civicrm\_financial\_type and 3 respectively. This should not be there as this group of fields are meant to be unique. To remove this error, you can -
  
  * Open `civicrm_entity_financial_account` table.
  * Search for rows that match `entity_id = 5`, `entity_table = civicrm_financial_type` and `account_relationship = 3`. You'll get two rows(This table should allow only one after indexing), delete one of them and re-execute `Update Indices` button. This is not provided by core as of now, so we have to do this manually.
  
  > **Comments:**
  > **username_0**: I applied the PR suggested, and then Civi listed one index that I removed which wasn't the one listed above. Then reran the update and got exactly the same error as above. So no further forward.  Suggestions?  Shouldn't Civi be able to cope with problems like this? Is there a reason this has to be sorted manually?  
  > **username_4**: Updated the answer.  
  > **username_5**: Applied the PR. The System Status now says there is an issue with civicrm_case_contact.case_id and .contact_id, but it won't let me drop these two because they're needed in a foreign key constraint.   Tried to remove the foreign key (ALTER TABLE civicrm_case_contact DROP FOREIGN KEY civicrm_case_contact.case_id ;) but then get the message "Can't DROP 'case_id'; check that column/key exists".  I have tried the 'Update indices' button but it just reloads the System Status page with no changes. Any ideas?  
  > **username_3**: @username_5 this answer might be helpful https://civicrm.stackexchange.com/questions/18487/how-to-find-and-or-fix-missing-indices/19424#comment22161_19424  
  > **username_5**: @username_3 perfect, thank you (and thanks to Artful Robot!)  
  
  ---
  
  