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.

Black
3,4094 gold badges44 silver badges131 bronze badges
asked Mar 18, 2020 at 11:29
5
  • Did you found any solution for this error. if Yes, Please Share the Solution. Thanks. Commented Mar 27, 2020 at 18:23
  • 1
    Did you find this solution ? i am also getting this. Commented May 22, 2020 at 17:31
  • @sumeetbajaj: Did you find this solution? I am also getting this. Commented Nov 12, 2020 at 12:02
  • @VishalThakur: Did you find this solution? I am also getting this. Commented Nov 12, 2020 at 12:03
  • @BalwantSingh no bro. Commented Nov 12, 2020 at 20:12

4 Answers 4

1

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!

answered Apr 2, 2020 at 10:04
1
  • Not worked for me. Commented Nov 12, 2020 at 12:03
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

answered Apr 1, 2020 at 17:23
1
  • Did you find this solution? I am also getting this. Commented Nov 12, 2020 at 12:05
0

If you are adding foreign key with the catalog_product_entity table or any other Magento2 core table then you need to match the column data type and other information with the table you are creating for your module. They both should match.

Bhaumik Upadhyay
9031 gold badge9 silver badges18 bronze badges
answered Nov 10, 2020 at 14:16
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

answered Aug 13, 2020 at 1:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.