Answers.Body: <p>The SQL here isn't trying to drop the field - it's trying to drop the foreign key.  So checking for the field isn't sufficient.  You can look for foreign keys with:</p>
  
  <pre><code>SHOW CREATE TABLE civicrm_action_schedule;
  </code></pre>
  
  <p>This will give you the exact SQL statement needed to create the table as it currently exists, and will show foreign keys.</p>
  
  <p>I have no idea how you ended up without the foreign key on that table.  However, there's no harm in removing that statement from the upgrade SQL if that foreign key already doesn't exist.  So after unzipping CiviCRM and before you run the database upgrade, edit <code>&lt;civicrmroot&gt;/CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl</code> and remove the offending SQL command (it's near the top!).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-10T05:06:46.293Z
Answers.LastActivityDate: 2016-05-10T05:06:46.293Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>I was running a 4.6 instance of CiviCRM and am attempting to upgrade to 4.7. Every time I initiate an upgrade, things work well until it reaches 4.7alpha stage of the upgrade. Then I get an error that I cannot drop mapping_id from the civicrm_action_schedule table. I've retried this several times with the same result. I checked and both the table and field exist in the original table. Any ideas about how to resolve this?</p>
  
  <p>Here is a screenshot of the error:</p>
  
  <p><a href="https://i.sstatic.net/7WgOj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7WgOj.png" alt="Error Mssg"></a></p>
  
  <p>[EDIT:  Adding searchable text from someone with the same issue to make this easier to find]</p>
  
  <pre><code> * ERROR USERINFO: ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_schedule_mapping_id` [nativecode=1091 ** Can't DROP 'FK_civicrm_action_schedule_mapping_id'; check that column/key exists]
   * ERROR DEBUGINFO: ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_schedule_mapping_id` [nativecode=1091 ** Can't DROP 'FK_civicrm_action_schedule_mapping_id'; check that column/key exists]
  #0 [internal function](): CRM_Core_Error::exceptionHandler(Object(DB_Error))
  #1 /usr/share/drupal7/modules/civicrm/packages/PEAR.php(931): call_user_func((Array:2), Object(DB_Error))
  #2 /usr/share/drupal7/modules/civicrm/packages/DB.php(976): PEAR_Error-&gt;PEAR_Error("DB Error: not found", -4, 16, (Array:2), "ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_sch...")
  #3 /usr/share/drupal7/modules/civicrm/packages/PEAR.php(564): DB_Error-&gt;DB_Error(-4, 16, (Array:2), "ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_sch...")
  #4 /usr/share/drupal7/modules/civicrm/packages/DB/common.php(1905): PEAR-&gt;raiseError(NULL, -4, NULL, NULL, "ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_sch...", "DB_Error", TRUE)
  #5 /usr/share/drupal7/modules/civicrm/packages/DB/mysql.php(895): DB_common-&gt;raiseError(-4, NULL, NULL, NULL, "1091 ** Can't DROP 'FK_civicrm_action_schedule_mapping_id'; check that column...")
  #6 /usr/share/drupal7/modules/civicrm/packages/DB/mysql.php(328): DB_mysql-&gt;mysqlRaiseError()
  #7 /usr/share/drupal7/modules/civicrm/packages/DB/common.php(1216): DB_mysql-&gt;simpleQuery("ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_sch...")
  #8 /usr/share/drupal7/modules/civicrm/CRM/Utils/File.php(332): DB_common-&gt;query("ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_sch...")
  #9 /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Form.php(196): CRM_Utils_File::sourceSQLFile("mysql://root:asdf@localhost/civicrm?new_link=true", "-- Add new columns for multilingual purpose\nALTER TABLE `civicrm_action_sche...", NULL, TRUE)
  #10 /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Form.php(387): CRM_Upgrade_Form-&gt;source("-- Add new columns for multilingual purpose\nALTER TABLE `civicrm_action_sche...", TRUE)
  #11 /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Form.php(421): CRM_Upgrade_Form-&gt;processLocales("/usr/share/drupal7/modules/civicrm/CRM/Upgrade/Incremental/sql/4.7.alpha1.mys...", "4.7.alpha1")
  #12 /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Incremental/Base.php(80): CRM_Upgrade_Form-&gt;processSQL("4.7.alpha1")
  #13 [internal function](): CRM_Upgrade_Incremental_Base::runSql(Object(CRM_Queue_TaskContext), "4.7.alpha1")
  #14 /usr/share/drupal7/modules/civicrm/CRM/Queue/Task.php(88): call_user_func_array((Array:2), (Array:2))
  #15 /usr/share/drupal7/modules/civicrm/CRM/Queue/Runner.php(214): CRM_Queue_Task-&gt;run(Object(CRM_Queue_TaskContext))
  #16 /usr/share/drupal7/modules/civicrm/CRM/Queue/Runner.php(168): CRM_Queue_Runner-&gt;runNext()
  #17 /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Headless.php(67): CRM_Queue_Runner-&gt;runAll()
  #18 /usr/share/drupal7/modules/civicrm/drupal/drush/civicrm.drush.inc(707): CRM_Upgrade_Headless-&gt;run()
  #19 [internal function](): drush_civicrm_upgrade_db()
  #20 /usr/share/php/drush/includes/command.inc(334): call_user_func_array("drush_civicrm_upgrade_db", (Array:0))
  #21 /usr/share/php/drush/includes/command.inc(208): _drush_invoke_hooks("civicrm-upgrade-db", (Array:0), "civicrm")
  #22 [internal function](): drush_command()
  #23 /usr/share/php/drush/includes/command.inc(175): call_user_func_array("drush_command", (Array:0))
  #24 /usr/share/php/drush/drush.php(92): drush_dispatch((Array:27))
  #25 /usr/share/php/drush/drush.php(61): _drush_bootstrap_and_dispatch()
  #26 /usr/share/php/drush/drush.php(16): drush_main()
  #27 {main}
  WD php: PEAR_Exception: DB Error: not found in CRM_Core_Error::exceptionHandler() (line 913 of                                      [error]
  /usr/share/drupal7/modules/civicrm/CRM/Core/Error.php).
  Cannot modify header information - headers already sent by (output started at                                                       [warning]
  /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Headless.php:72) bootstrap.inc:1232
  PEAR_Exception: DB Error: not found in CRM_Core_Error::exceptionHandler() (line 913 of /usr/share/drupal7/modules/civicrm/CRM/Core/Error.php).
  Drush command terminated abnormally due to an unrecoverable error.                                                                  [error]
  </code></pre>
  
Tags: <upgrade>
Title: Database Error When Upgrading 4.6 to 4.7 on Drupal 7
ThreadText: # Database Error When Upgrading 4.6 to 4.7 on Drupal 7
  
  (Asked by: username_0 on 2016-03-22)
  
  I was running a 4.6 instance of CiviCRM and am attempting to upgrade to 4.7. Every time I initiate an upgrade, things work well until it reaches 4.7alpha stage of the upgrade. Then I get an error that I cannot drop mapping_id from the civicrm_action_schedule table. I've retried this several times with the same result. I checked and both the table and field exist in the original table. Any ideas about how to resolve this?
  Here is a screenshot of the error:
  
  [EDIT:  Adding searchable text from someone with the same issue to make this easier to find]
   * ERROR USERINFO: ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_schedule_mapping_id` [nativecode=1091 ** Can't DROP 'FK_civicrm_action_schedule_mapping_id'; check that column/key exists]
   * ERROR DEBUGINFO: ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_schedule_mapping_id` [nativecode=1091 ** Can't DROP 'FK_civicrm_action_schedule_mapping_id'; check that column/key exists]
  #0 [internal function](): CRM_Core_Error::exceptionHandler(Object(DB_Error))
  #1 /usr/share/drupal7/modules/civicrm/packages/PEAR.php(931): call_user_func((Array:2), Object(DB_Error))
  #2 /usr/share/drupal7/modules/civicrm/packages/DB.php(976): PEAR_Error->PEAR_Error("DB Error: not found", -4, 16, (Array:2), "ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_sch...")
  #3 /usr/share/drupal7/modules/civicrm/packages/PEAR.php(564): DB_Error->DB_Error(-4, 16, (Array:2), "ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_sch...")
  #4 /usr/share/drupal7/modules/civicrm/packages/DB/common.php(1905): PEAR->raiseError(NULL, -4, NULL, NULL, "ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_sch...", "DB_Error", TRUE)
  #5 /usr/share/drupal7/modules/civicrm/packages/DB/mysql.php(895): DB_common->raiseError(-4, NULL, NULL, NULL, "1091 ** Can't DROP 'FK_civicrm_action_schedule_mapping_id'; check that column...")
  #6 /usr/share/drupal7/modules/civicrm/packages/DB/mysql.php(328): DB_mysql->mysqlRaiseError()
  #7 /usr/share/drupal7/modules/civicrm/packages/DB/common.php(1216): DB_mysql->simpleQuery("ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_sch...")
  #8 /usr/share/drupal7/modules/civicrm/CRM/Utils/File.php(332): DB_common->query("ALTER TABLE `civicrm_action_schedule` DROP FOREIGN KEY `FK_civicrm_action_sch...")
  #9 /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Form.php(196): CRM_Utils_File::sourceSQLFile("mysql://root:asdf@localhost/civicrm?new_link=true", "-- Add new columns for multilingual purpose\nALTER TABLE `civicrm_action_sche...", NULL, TRUE)
  #10 /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Form.php(387): CRM_Upgrade_Form->source("-- Add new columns for multilingual purpose\nALTER TABLE `civicrm_action_sche...", TRUE)
  #11 /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Form.php(421): CRM_Upgrade_Form->processLocales("/usr/share/drupal7/modules/civicrm/CRM/Upgrade/Incremental/sql/4.7.alpha1.mys...", "4.7.alpha1")
  #12 /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Incremental/Base.php(80): CRM_Upgrade_Form->processSQL("4.7.alpha1")
  #13 [internal function](): CRM_Upgrade_Incremental_Base::runSql(Object(CRM_Queue_TaskContext), "4.7.alpha1")
  #14 /usr/share/drupal7/modules/civicrm/CRM/Queue/Task.php(88): call_user_func_array((Array:2), (Array:2))
  #15 /usr/share/drupal7/modules/civicrm/CRM/Queue/Runner.php(214): CRM_Queue_Task->run(Object(CRM_Queue_TaskContext))
  #16 /usr/share/drupal7/modules/civicrm/CRM/Queue/Runner.php(168): CRM_Queue_Runner->runNext()
  #17 /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Headless.php(67): CRM_Queue_Runner->runAll()
  #18 /usr/share/drupal7/modules/civicrm/drupal/drush/civicrm.drush.inc(707): CRM_Upgrade_Headless->run()
  #19 [internal function](): drush_civicrm_upgrade_db()
  #20 /usr/share/php/drush/includes/command.inc(334): call_user_func_array("drush_civicrm_upgrade_db", (Array:0))
  #21 /usr/share/php/drush/includes/command.inc(208): _drush_invoke_hooks("civicrm-upgrade-db", (Array:0), "civicrm")
  #22 [internal function](): drush_command()
  #23 /usr/share/php/drush/includes/command.inc(175): call_user_func_array("drush_command", (Array:0))
  #24 /usr/share/php/drush/drush.php(92): drush_dispatch((Array:27))
  #25 /usr/share/php/drush/drush.php(61): _drush_bootstrap_and_dispatch()
  #26 /usr/share/php/drush/drush.php(16): drush_main()
  #27 {main}
  WD php: PEAR_Exception: DB Error: not found in CRM_Core_Error::exceptionHandler() (line 913 of                                      [error]
  /usr/share/drupal7/modules/civicrm/CRM/Core/Error.php).
  Cannot modify header information - headers already sent by (output started at                                                       [warning]
  /usr/share/drupal7/modules/civicrm/CRM/Upgrade/Headless.php:72) bootstrap.inc:1232
  PEAR_Exception: DB Error: not found in CRM_Core_Error::exceptionHandler() (line 913 of /usr/share/drupal7/modules/civicrm/CRM/Core/Error.php).
  Drush command terminated abnormally due to an unrecoverable error.                                                                  [error]
  
  **Tags:** upgrade
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-05-10. Score: 1
  
  The SQL here isn't trying to drop the field - it's trying to drop the foreign key.  So checking for the field isn't sufficient.  You can look for foreign keys with:
  SHOW CREATE TABLE civicrm_action_schedule;
  
  This will give you the exact SQL statement needed to create the table as it currently exists, and will show foreign keys.
  I have no idea how you ended up without the foreign key on that table.  However, there's no harm in removing that statement from the upgrade SQL if that foreign key already doesn't exist.  So after unzipping CiviCRM and before you run the database upgrade, edit /CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl and remove the offending SQL command (it's near the top!).
  
  
  ---
  
  