During upgrade from v1.5.1.0 to v1.6.0 it is trying to drop a key but can't because of a foreign key.

relevant lines in update script


I see in the code for lib/Varien/Db/Adapter/Pdo/Mysql.php

public function startSetup()
    $this->raw_query("SET SQL_MODE=''");

    return $this;

but obviously it doesn't work.

I placed $installer->getConnection()->raw_query("SET FOREIGN_KEY_CHECKS=0;"); right before the relevant query to alter the table, but it has no useful effect.

I then made and ran a script to drop all foreign keys from the magento database. I confirmed that the foreign key is gone before starting the upgrade, but after starting the upgrade the foreign keys get added back in and start causing problems again.

So how do I properly disable foreign key checks or prevent the foreign keys from being added back in?

2 Answers 2


Do you have access to MYSQL cmd-line on the Magento server? If yes, you should be able to globally disable foreign key checks during your upgrade, then re-enable when you are done.

  1. Open a command-line interface on the machine running magento. If you are on a Mac, open a new terminal window. If your magento is on a remote machine you can SSH to the box - from Mac you can use a terminal window, from PC you can use Putty.

  2. Once you are connected to the Magento server, open MYSQL cmd-line, you can use the database username and password from your Magento instance (in M1, info can be found app/etc/local.xml).

For example, if you have SSH access, the commands would be as follows:

[userX@magento-server userX]# mysql -u magentoDbUser -p
Enter password: 

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10013
Server version: 10.4.7-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
| Database           |
| information_schema |
| mysql              |
| performance_schema |
| magento1          |
4 rows in set (0.007 sec)

MariaDB [(none)]> use magento1;
Database changed

MariaDB [magento1]> SET FOREIGN_KEY_CHECKS=0;
Query OK, 0 rows affected (0.000 sec)


MariaDB [magento1]> SET FOREIGN_KEY_CHECKS=1;
Query OK, 0 rows affected (0.000 sec)

MariaDB [magento1]> exit
  • if this would work then I would expect the SET FOREIGN_KEY_CHECKS=0; to work when placed within the upgrade script (I tried it just in case I was wrong, didn't work), I believe the problem is that FOREIGN_KEY_CHECKS doesn't apply to the requirement that the local column have an index applied to it. Sep 13, 2019 at 19:07

Turns out it was all due to incompatibilities in the newer versions of mysql and php. I setup different systems with outdated software to handle each stage of the upgrade with corresponding versions of mysql, php, and magento, and the update went smoothly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.