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_itemMODIFY COLUMNitem_idint(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT "Item Id", ADD CONSTRAINT PRIMARY KEY (item_id), ADD CONSTRAINTQUOTE_ITEM_PARENT_ITEM_ID_QUOTE_ITEM_ITEM_IDFOREIGN KEY (parent_item_id) REFERENCESquote_item(item_id) ON DELETE CASCADE, ADD CONSTRAINTQUOTE_ITEM_QUOTE_ID_QUOTE_ENTITY_IDFOREIGN KEY (quote_id) REFERENCESquote(entity_id) ON DELETE CASCADE, ADD CONSTRAINTQUOTE_ITEM_STORE_ID_STORE_STORE_IDFOREIGN KEY (store_id) REFERENCESstore(store_id) ON DELETE SET NULL, ADD INDEXQUOTE_ITEM_PARENT_ITEM_ID(parent_item_id), ADD INDEXQUOTE_ITEM_PRODUCT_ID(product_id), ADD INDEXQUOTE_ITEM_QUOTE_ID(quote_id), ADD INDEXQUOTE_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– Vishal Thakur2020年03月27日 18:23:45 +00:00Commented Mar 27, 2020 at 18:23
-
1Did you find this solution ? i am also getting this.sumeet bajaj– sumeet bajaj2020年05月22日 17:31:15 +00:00Commented May 22, 2020 at 17:31
-
@sumeetbajaj: Did you find this solution? I am also getting this.Balwant Singh– Balwant Singh2020年11月12日 12:02:47 +00:00Commented Nov 12, 2020 at 12:02
-
@VishalThakur: Did you find this solution? I am also getting this.Balwant Singh– Balwant Singh2020年11月12日 12:03:03 +00:00Commented Nov 12, 2020 at 12:03
-
@BalwantSingh no bro.Vishal Thakur– Vishal Thakur2020年11月12日 20:12:49 +00:00Commented Nov 12, 2020 at 20:12
4 Answers 4
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!
-
Not worked for me.Balwant Singh– Balwant Singh2020年11月12日 12:03:44 +00:00Commented Nov 12, 2020 at 12:03
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
-
Did you find this solution? I am also getting this.Balwant Singh– Balwant Singh2020年11月12日 12:05:44 +00:00Commented Nov 12, 2020 at 12:05
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.
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
Explore related questions
See similar questions with these tags.