Skip to main content

Upgrading Magento 2 can be tricky. When recently updating a Magento 2.4.5-p2 website to 2.4.6-p2, I encountered the following error after running bin/magento setup:upgrade.

1061 Duplicate key name ‘WISHLIST_CUSTOMER_ID’

SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'WISHLIST_CUSTOMER_ID', query was: ALTER TABLE wishlist ADD CONSTRAINT WISHLIST_CUSTOMER_ID UNIQUE KEY (customer_id)
WISHLIST_CUSTOMER_ID error

What causes the WISHLIST_CUSTOMER_ID error?

There’s some suggestion that this is related to the WeltPixel Pearl theme and the WeltPixel_AdvancedWishlist module. The site was indeed using the WeltPixel theme. Other users reported that the issue can remain even if the theme is removed.

Magento WISHLIST_CUSTOMER_ID error

How to fix Duplicate key name ‘WISHLIST_CUSTOMER_ID’

Magento 2 support suggested renaming the existing index for the wishlist table as a workaround.

ALTER TABLE wishlist CHANGE COLUMN customer_id customer_id2 int unsigned default 0 not null comment 'Customer ID';

For me, this merely altered the error message rather than fixing the issue.

SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'WISHLIST_CUSTOMER_ID', query was: ALTER TABLE wishlist ADD COLUMN customer_id int UNSIGNED NOT NULL DEFAULT 0 COMMENT "Customer ID", ADD CONSTRAINT WISHLIST_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID FOREIGN KEY (customer_id) REFERENCES customer_entity (entity_id) ON DELETE CASCADE, ADD CONSTRAINT WISHLIST_CUSTOMER_ID UNIQUE KEY (customer_id)
Magento 2 WISHLIST_CUSTOMER_ID error

Another WeltPixel Pro theme user advised disabling the module first;

php bin/magento module:disable WeltPixel_AdvancedWishlist

The module wasn’t enabled in my case.

Solution to Duplicate key name ‘WISHLIST_CUSTOMER_ID’

The solution for me was found by GitHub user nickpiro in the thread M2.2.8 to M2.3.3 Upgrade Wishlist Duplicate Key Name.

I’ve been able to resolve it by removing the following from the db_schema.xml.

<constraint xsi:type="unique" referenceId="WISHLIST_CUSTOMER_ID"> <column name="customer_id"/> </constraint>

In a Composer install the file is found at;

/vendor/magento/module-wishlist/etc/db_schema.xml

Typical of a Magento upgrade, it wasn’t the only error. I also hit;

TypeError: addslashes(): Argument #1 ($string) must be of type string

This issue is now patched but can be manually fixed by altering line 62 -63 of;

vendor\magento\module-theme\Block\Html\Header.php

These two lines should be replaced with;

return $this->escaper->escapeQuote(__($this->_data['welcome'])->render(), true);

I hope that helped fix your Magento 2 upgrade issue.

Andrew Taylor

A senior UI designer with over 25 years of web design and web development experience working for some of the largest companies in the UK. An expert in all things Magento and WordPress.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.