3

I have moved my website files and DB from one server to another.

Now, When I am running setup:upgrade command. I am getting below error:

Updating modules: Schema creation/updates:

SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint, query was: ALTER TABLE quote_item MODIFY COLUMN item_id int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT "Item Id", ADD CONSTRAINT PRIMARY KEY (item_id), ADD CONSTRAINT QUOTE_ITEM_PARENT_ITEM_ID_QUOTE_ITEM_ITEM_ID FOREIGN KEY (parent_item_id) REFERENCES quote_item (item_id) ON DELETE CASCADE, ADD CONSTRAINT QUOTE_ITEM_QUOTE_ID_QUOTE_ENTITY_ID FOREIGN KEY (quote_id) REFERENCES quote (entity_id) ON DELETE CASCADE, ADD CONSTRAINT QUOTE_ITEM_STORE_ID_STORE_STORE_ID FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE SET NULL, ADD INDEX QUOTE_ITEM_PARENT_ITEM_ID (parent_item_id), ADD INDEX QUOTE_ITEM_PRODUCT_ID (product_id), ADD INDEX QUOTE_ITEM_QUOTE_ID (quote_id), ADD INDEX QUOTE_ITEM_STORE_ID (store_id)

Please help to get rid of this error.

  • Did you found any solution for this error. if Yes, Please Share the Solution. Thanks. – Vishal Thakur Mar 27 at 18:23
  • 1
    Did you find this solution ? i am also getting this. – sumeet bajaj May 22 at 17:31
0

I am getting the same error from last five days when I tried to upload on godaddy server from localhost. It is working fine at localhost but shown following error on server:

SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint, query was: ALTER TABLE quote_item MODIFY COLUMN item_id int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT "Item ID", ADD CONSTRAINT PRIMARY KEY (item_id), ADD CONSTRAINT QUOTE_ITEM_PARENT_ITEM_ID_QUOTE_ITEM_ITEM_ID FOREIGN KEY (parent_item_id) REFERENCES quote_item (item_id) ON DELETE CASCADE, ADD CONSTRAINT QUOTE_ITEM_QUOTE_ID_QUOTE_ENTITY_ID FOREIGN KEY (quote_id) REFERENCES quote (entity_id) ON DELETE CASCADE, ADD CONSTRAINT QUOTE_ITEM_STORE_ID_STORE_STORE_ID FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE SET NULL, ADD INDEX QUOTE_ITEM_PARENT_ITEM_ID (parent_item_id), ADD INDEX QUOTE_ITEM_PRODUCT_ID (product_id), ADD INDEX QUOTE_ITEM_QUOTE_ID (quote_id), ADD INDEX QUOTE_ITEM_STORE_ID (store_id)

Kindly help

| improve this answer | |
0

You need to run this query:

Select item_id from quote_item where parent_item_id is not null and parent_item_id in (select item_id from quote_item)

After that, the result will be updated and you need to fix it to parent_item_id = null.

Leave a comment if it works!

| improve this answer | |
0

To resolve this issue i would suggest you to run below commands in sequence :

rm -rf generated php bin/magento indexer:reindex php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy -f php bin/magento cache:clean php bin/magento cache:flush

then check also after running if its still not resolved then i would suggest to enabled developer mode for your setup and then run the same bunch of commands in sequence and then check !

Hope it helps

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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