Magento SQL 错误

发布于 2024-10-19 16:16:29 字数 166 浏览 4 评论 0原文

您是否知道

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1421062-85-1-2' for key 1

尝试保存产品(BO 和 FO)时出现的此错误

Do you have an idea about this error

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1421062-85-1-2' for key 1

it appears when trying to save a product (BO and FO)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乖不如嘢 2024-10-26 16:16:29

您的 ALTER TABLE 代码语法错误。前两行缺少两个 (。已更新:

ALTER TABLE `catalog_product_entity_decimal` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_int`  ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);

/* Add unique keys to customer eav tables */
ALTER TABLE `customer_entity_decimal` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_int`  ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);

/* Add unique keys to customer address eav tables */
ALTER TABLE `customer_address_entity_decimal` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_int`  ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);

Your syntax is wrong on the ALTER TABLE code. It's missing two ('s in the first two lines. Here's updated:

ALTER TABLE `catalog_product_entity_decimal` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_int`  ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);

/* Add unique keys to customer eav tables */
ALTER TABLE `customer_entity_decimal` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_int`  ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);

/* Add unique keys to customer address eav tables */
ALTER TABLE `customer_address_entity_decimal` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_int`  ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
夏末 2024-10-26 16:16:29

我在将 1.3 升级到 1.4 时遇到了同样的问题:事实证明,有很多重复的条目(是的,“这就是她说的”)。
解决方案是找到并消灭它们。这里是找到它们的代码:

SELECT `orig`.`entity_id`, 
   `orig`.`attribute_id`, 
   `orig`.`store_id`, 
   `orig`.`value` as `original_value`, 
   `duplicated`.`value` as `duplicated_value`
FROM `catalog_product_entity_decimal` as `orig` 
INNER JOIN `catalog_product_entity_decimal` as `duplicated` 
    ON (
         `orig`.`entity_id` = `duplicated`.`entity_id` 
         AND `orig`.`store_id` = `duplicated`.`store_id` 
         AND `orig`.`attribute_id` = `duplicated`.`attribute_id`
         AND `orig`.`value_id` > `duplicated`.`value_id`
   )

然后添加唯一键:

ALTER TABLE `catalog_product_entity_decimal` ADD UNIQUE KEY `IDX_BASE` `entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_int`  ADD UNIQUE KEY `IDX_BASE` `entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);

/* Add unique keys to customer eav tables */
ALTER TABLE `customer_entity_decimal` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_int`  ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);

/* Add unique keys to customer address eav tables */
ALTER TABLE `customer_address_entity_decimal` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_int`  ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);

并考虑乔纳森的评论:)

I've had this same problem when upgrading a 1.3 to 1.4: it turned out that there was a lot of duplicates entries (yay, "that's what she said").
Solution was to locate and eliminate them. Here the code to locate them:

SELECT `orig`.`entity_id`, 
   `orig`.`attribute_id`, 
   `orig`.`store_id`, 
   `orig`.`value` as `original_value`, 
   `duplicated`.`value` as `duplicated_value`
FROM `catalog_product_entity_decimal` as `orig` 
INNER JOIN `catalog_product_entity_decimal` as `duplicated` 
    ON (
         `orig`.`entity_id` = `duplicated`.`entity_id` 
         AND `orig`.`store_id` = `duplicated`.`store_id` 
         AND `orig`.`attribute_id` = `duplicated`.`attribute_id`
         AND `orig`.`value_id` > `duplicated`.`value_id`
   )

and then add the unique keys:

ALTER TABLE `catalog_product_entity_decimal` ADD UNIQUE KEY `IDX_BASE` `entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_int`  ADD UNIQUE KEY `IDX_BASE` `entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);
ALTER TABLE `catalog_product_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`);

/* Add unique keys to customer eav tables */
ALTER TABLE `customer_entity_decimal` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_int`  ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);

/* Add unique keys to customer address eav tables */
ALTER TABLE `customer_address_entity_decimal` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_int`  ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_varchar` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_text` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);
ALTER TABLE `customer_address_entity_datetime` ADD UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`);

And take Jonathan's comment into account :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文