Skip to content
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

Remove unused entity_id foreign key #7456

Merged
merged 1 commit into from
May 17, 2017

Conversation

mattjbarlow
Copy link
Contributor

@mattjbarlow mattjbarlow commented Nov 16, 2016

This PR fixes a bug that prevents Magento 2 from working with Amazon Aurora.

Steps To Reproduce

  1. Obtain the Magento code:
    composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition
  2. Build an AWS Aurora RDS instance.
  3. Configure app/etc/env.php to use the AWS Aurora RDS instance.
  4. Run the following command:
    php bin/magento setup:db-schema:upgrade

Expected Result

Success

Actual Result

  [PDOException]                                                         
  SQLSTATE[HY000]: General error: 1030 Got error 38 from storage engine 

InnoDB Logs

------------------------
LATEST FOREIGN KEY ERROR
------------------------
2016-11-14 23:22:42 2adea2388700 Error in foreign key constraint of table magento/catalog_product_entity_media_gallery:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
,
  CONSTRAINT "CAT_PRD_ENTT_MDA_GLR_ENTT_ID_CAT_PRD_ENTT_ENTT_ID" FOREIGN KEY ("entity_id") REFERENCES "catalog_product_entity" ("entity_id") ON DELETE CASCADE

Explanation

When catalog_product_entity_media_gallery is created, a foreign key is created on the column entity_id.

However, the entity_id column is dropped in the upgrade script here

On MariaDB 5.6, the php bin/magento setup:db-schema:upgrade completes successfully, but no foreign key is ever created.

However, on Amazon Aurora, as of their update last Friday, the same command results in error 38 as referenced above.

Since, either way, the foreign key does not appear to ever be created, I removed it from the InstallSchema.php file.

This removes the entity_id foreign key from the
catalog_product_entity_media_gallery table. The entity_id column is
dropped in UpgradeSchema.php, so the foreign key can never be created.
This patch fixes a fatal error on AWS Aurora.
@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Nov 16, 2016

CLA assistant check
All committers have signed the CLA.

@vrann
Copy link
Contributor

vrann commented May 16, 2017

@mattjbarlow Thank you for the report. Let me clarify, does exception happen when entity_id column is being dropped?

@vrann
Copy link
Contributor

vrann commented May 16, 2017

@mattjbarlow Anyway it is a good improvement, accepting

@magento-team
Copy link
Contributor

@mattjbarlow Thank you for the contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants