Answers.Body: <p>The upgrade for 4.7.18 tries to insert new state in <code>civicrm_state_province</code> table. This was done via <a href="https://issues.civicrm.org/jira/browse/CRM-19993" rel="nofollow noreferrer">https://issues.civicrm.org/jira/browse/CRM-19993</a>.</p>
  
  <p>But seems you already have <code>Chandigarh</code> in the table due to which mysql finds a duplicate row already present in the database and eventually displays an error. So the question is how this record is already present in your database?</p>
  
  <ul>
  <li>Have you tried this upgrade for 4.7.18 before and retrying this again? If yes, try getting a backup of the previous version and then start the upgrade process.</li>
  <li>Have you added the new state <code>Chandigarh</code> in your DB manually in your previous version? 
  In this case, you can simply delete the <code>Chandigarh</code> entry manually from <code>civicrm_state_province</code> table and restart the upgrade. It will create the entry for Chandigarh so you'll not lose any state record from your DB.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-15T09:36:26.013Z
Answers.Text: I think you should not delete entries from table since it might have been used in other tables so probably its a good idea to remove the line of code from upgrade script.
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-16T13:01:05.283Z
Answers.Text: Hi @PradeepNayak,how can I identify the line of code where this insert code is present?
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-16T13:38:17.833Z
Answers.Text: https://github.com/civicrm/civicrm-core/blob/4.7.18-rc/CRM/Upgrade/Incremental/sql/4.7.18.mysql.tpl#L56
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-15T06:33:40.130Z
Answers.LastActivityDate: 2018-09-15T06:33:40.130Z
Answers.UserDisplayName: jitendra - fuzion
Body: <p>[Error: Upgrade DB to 4.7.18: SQL] 
   [nativecode=1062 ** Duplicate entry 'Chandigarh-1101' for key 'UI_name_country_id']</p>
  
  <p>How can I fix the error as given below:</p>
  
  <pre><code>INSERT INTO `civicrm_state_province` (`id`, `country_id`, `abbreviation`, `name`) VALUES (NULL, 1101, "CH", "Chandigarh"), (NULL, 1083, "CP", "Central"), (NULL, 1083, "EP", "Eastern"), (NULL, 1083, "NP", "Northern"), (NULL, 1083, "WP", "Western"), (NULL, 1181, "K", "Saint Kitts"), (NULL, 1181, "N", "Nevis"), (NULL, 1190, "E", "Eastern"), (NULL, 1190, "N", "Northern"), (NULL, 1190, "S", "Southern") [nativecode=1062 ** Duplicate entry 'Chandigarh-1101' for key 'UI_name_country_id']
  DebugInfo   INSERT INTO `civicrm_state_province` (`id`, `country_id`, `abbreviation`, `name`) VALUES (NULL, 1101, "CH", "Chandigarh"), (NULL, 1083, "CP", "Central"), (NULL, 1083, "EP", "Eastern"), (NULL, 1083, "NP", "Northern"), (NULL, 1083, "WP", "Western"), (NULL, 1181, "K", "Saint Kitts"), (NULL, 1181, "N", "Nevis"), (NULL, 1190, "E", "Eastern"), (NULL, 1190, "N", "Northern"), (NULL, 1190, "S", "Southern") [nativecode=1062 ** Duplicate entry 'Chandigarh-1101' for key 'UI_name_country_id']
  </code></pre>
  
  <p><a href="https://i.sstatic.net/4wrSh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4wrSh.png" alt="enter image description here"></a></p>
  
Tags: <upgrade><database>
Title: Error Upgrading DB to 4.7.18: SQL
ThreadText: # Error Upgrading DB to 4.7.18: SQL
  
  (Asked by: username_0 on 2018-09-15)
  
  [Error: Upgrade DB to 4.7.18: SQL] 
   [nativecode=1062 ** Duplicate entry 'Chandigarh-1101' for key 'UI_name_country_id']
  How can I fix the error as given below:
  INSERT INTO `civicrm_state_province` (`id`, `country_id`, `abbreviation`, `name`) VALUES (NULL, 1101, "CH", "Chandigarh"), (NULL, 1083, "CP", "Central"), (NULL, 1083, "EP", "Eastern"), (NULL, 1083, "NP", "Northern"), (NULL, 1083, "WP", "Western"), (NULL, 1181, "K", "Saint Kitts"), (NULL, 1181, "N", "Nevis"), (NULL, 1190, "E", "Eastern"), (NULL, 1190, "N", "Northern"), (NULL, 1190, "S", "Southern") [nativecode=1062 ** Duplicate entry 'Chandigarh-1101' for key 'UI_name_country_id']
  DebugInfo   INSERT INTO `civicrm_state_province` (`id`, `country_id`, `abbreviation`, `name`) VALUES (NULL, 1101, "CH", "Chandigarh"), (NULL, 1083, "CP", "Central"), (NULL, 1083, "EP", "Eastern"), (NULL, 1083, "NP", "Northern"), (NULL, 1083, "WP", "Western"), (NULL, 1181, "K", "Saint Kitts"), (NULL, 1181, "N", "Nevis"), (NULL, 1190, "E", "Eastern"), (NULL, 1190, "N", "Northern"), (NULL, 1190, "S", "Southern") [nativecode=1062 ** Duplicate entry 'Chandigarh-1101' for key 'UI_name_country_id']
  
  **Tags:** upgrade, database
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-09-15. Score: 1
  
  The upgrade for 4.7.18 tries to insert new state in `civicrm_state_province` table. This was done via <https://issues.civicrm.org/jira/browse/CRM-19993>.
  
  But seems you already have `Chandigarh` in the table due to which mysql finds a duplicate row already present in the database and eventually displays an error. So the question is how this record is already present in your database?
  
  * Have you tried this upgrade for 4.7.18 before and retrying this again? If yes, try getting a backup of the previous version and then start the upgrade process.
  * Have you added the new state `Chandigarh` in your DB manually in your previous version?
    In this case, you can simply delete the `Chandigarh` entry manually from `civicrm_state_province` table and restart the upgrade. It will create the entry for Chandigarh so you'll not lose any state record from your DB.
  
  > **Comments:**
  > **username_2**: I think you should not delete entries from table since it might have been used in other tables so probably its a good idea to remove the line of code from upgrade script.  
  > **username_0**: Hi @PradeepNayak,how can I identify the line of code where this insert code is present?  
  > **username_2**: https://github.com/civicrm/civicrm-core/blob/4.7.18-rc/CRM/Upgrade/Incremental/sql/4.7.18.mysql.tpl#L56  
  
  ---
  
  