Skip to content

Unable to upgrade from <1.1.22 to 1.1.26 due to SQL error #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
captain-melanie opened this issue Aug 25, 2021 · 4 comments
Closed

Unable to upgrade from <1.1.22 to 1.1.26 due to SQL error #99

captain-melanie opened this issue Aug 25, 2021 · 4 comments

Comments

@captain-melanie
Copy link
Contributor

captain-melanie commented Aug 25, 2021

Hi, we have setup_version v1.1.21 installed and would like to upgrade to setup_version v1.1.26, but a sql error in the upgrade script broke the whole process. You could reproduce the error by upgrading v1.1.21 to v1.1.26.

$ php bin/magento setup:upgrade

...
Module 'ShipperHQ_Common':
Module 'ShipperHQ_Logger':
Module 'ShipperHQ_Shipper':
Upgrading schema.. SQLSTATE[HY000]: General error: 1553 Cannot drop index 'SHIPPERHQ_ORDER_DETAIL_GRID_ORDER_ID': needed in a foreign key constraint

In log:

SQLSTATE[HY000]: General error: 1553 Cannot drop index 'SHIPPERHQ_ORDER_DETAIL_GRID_ORDER_ID': needed in a foreign key constraint, query was: ALTER TABLE `shipperhq_order_detail_grid` DROP KEY `SHIPPERHQ_ORDER_DETAIL_GRID_ORDER_ID`

We found that the error comes from this line https://github.com/shipperhq/module-shipper/blob/main/src/Setup/UpgradeSchema.php#L990 where the script tries to drop an index but fails due to a foreign key constraint in MySQL https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html. MySQL requires at least 1 index on foreign key. This constraint is consistent across MySQL versions.

MySQL requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan. In the referencing table, there must be an index where the foreign key columns are listed as the first columns in the same order. Such an index is created on the referencing table automatically if it does not exist. This index might be silently dropped later if you create another index that can be used to enforce the foreign key constraint. index_name, if given, is used as described previously.

To fix this issue, we could add a temporary index to satisfy the constraint then drop it once the proper index has been added to the table.

pr: #100

@wsadasmit
Copy link
Contributor

wsadasmit commented Aug 31, 2021

Hi @captain-melanie ,
I've installed module-shipper version 20.25.0 (the version with setup_version v1.1.21) to a fresh instance of Magento 2.4.3, and then upgraded via the process outlined in our install docs, and did not encounter this issue.

If you'd like to troubleshoot this further, can you please send details of your environment including Magento version and PHP version to [email protected]? Thanks,

@brunogemelli
Copy link

Same issue for me. I think it is related to the MySQL version.

@wsadasmit can you test it using MySQL 5.7 or higher?

@wsajosh
Copy link
Contributor

wsajosh commented Nov 1, 2021

Issue has been replicated. Thanks for the PR @captain-melanie

@wsajosh wsajosh reopened this Nov 1, 2021
@wsajosh
Copy link
Contributor

wsajosh commented Nov 1, 2021

Thanks for raising this issue. We'll be creating a new release shortly which addresses it. Thanks for the fix @captain-melanie !

@wsajosh wsajosh closed this as completed Nov 1, 2021
wsajosh added a commit that referenced this issue Nov 1, 2021
…upgrade-schema

#99 Bugfix/fix sql error in upgrade schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants