MySQL magento SQLSTATE[23000]:违反完整性约束:1062 键“PRIMARY”的重复条目“363624”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15868106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:15:11  来源:igfitidea点击:

magento SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '363624' for key 'PRIMARY'

mysqlmagento

提问by lior r

i have migrated a mgento installation doing the following:

我已经迁移了一个 mgento 安装,执行以下操作:

  1. copied all files
  2. exported the db
  3. imported the db using mysql workbench
  4. changed the base_url's to the new domain
  5. updated local.xml to the correct settings
  1. 复制了所有文件
  2. 导出数据库
  3. 使用 mysql 工作台导入数据库
  4. 将 base_url 更改为新域
  5. 将 local.xml 更新为正确的设置

now im getting:

现在我得到:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '363624' for key 'PRIMARY'

I have searched the db for this key 363624 , but it is not duplicated as the messages says

我已经在数据库中搜索了这个键 363624 ,但它没有像消息所说的那样重复

how can i solve this ?

我该如何解决这个问题?

回答by Oscar

This helped me (clearing some of the tables):

这对我有帮助(清除一些表格):

Enter your Magento database and run following sql query:

输入您的 Magento 数据库并运行以下 sql 查询:

TRUNCATE dataflow_batch_export ; 
TRUNCATE dataflow_batch_import ; 
TRUNCATE log_customer ; 
TRUNCATE log_quote ; 
TRUNCATE log_summary ; 
TRUNCATE log_summary_type ; 
TRUNCATE log_url ; 
TRUNCATE log_url_info ; 
TRUNCATE log_visitor ; 
TRUNCATE log_visitor_info ; 
TRUNCATE log_visitor_online ; 
TRUNCATE report_event ;

After that need to clear var/session dir (If your session stored in files) cause you will get same error until you clear session files.

之后需要清除 var/session 目录(如果您的会话存储在文件中)导致您将收到相同的错误,直到您清除会话文件。

回答by redjam13

It is not duplicated but rather something must be tryingto duplicate it.

它不是复制的,而是某种东西必须试图复制它。

How did you export the database? I would check that the dumped SQL file has the line "SET FOREIGN_KEY_CHECKS=0;" or similar at the top.

你是怎么导出数据库的?我会检查转储的 SQL 文件在顶部是否有“ SET FOREIGN_KEY_CHECKS=0;”或类似的行。

If not, I would drop the database and add this line to the top of the file:

如果没有,我将删除数据库并将此行添加到文件顶部:

SET FOREIGN_KEY_CHECKS=0;

SET FOREIGN_KEY_CHECKS=0;

... and this line to the bottom:

...这行到底部:

SET FOREIGN_KEY_CHECKS=1;

SET FOREIGN_KEY_CHECKS=1;

... then try again.

……然后再试一次。

回答by creuzerm

I was getting the same error.

我遇到了同样的错误。

For me, it turns out that the export was taking so long with the site staying 'live' that the end of the export was out of sync with the beginning.

对我来说,结果证明导出需要很长时间,站点保持“实时”,导出的结束与开始不同步。

Specifically, the 'log_visitor_info' table had about 100 more records than some of the other related visitor log tables, so the DB is trying to create a record ID from another table that already exists here.

具体来说,“log_visitor_info”表的记录比其他一些相关的访问者日志表多约 100 条记录,因此数据库正在尝试从此处已存在的另一个表创建记录 ID。

I just deleted the last 100 or so records from this specific table and things worked again without the error. Alternatively it looks like you can mash on the f5 key until you increment past that already-existing ID and Magento will start working again.

我刚刚从这个特定表中删除了最后 100 条左右的记录,并且一切正常,没有出现错误。或者,您似乎可以混合 f5 键,直到您增加超过现有的 ID,Magento 将再次开始工作。

I suspect that putting the store in maintenance mode before the export may help with this particular error.

我怀疑在导出之前将商店置于维护模式可能有助于解决此特定错误。

回答by fr4gm3nt

In my case the problem was UTF-8 without BOM encoding in text editor. I've change to UTF-8 with BOM and everything works fine.

就我而言,问题是在文本编辑器中没有 BOM 编码的 UTF-8。我已更改为带有 BOM 的 UTF-8,一切正常。

回答by bhupendra

if the error showing for the table 'cataloginventory_stock_item' having 'UNQ_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID' index,

如果表格显示错误 'cataloginventory_stock_item' having 'UNQ_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID' index,

then please sure that you are passing different product SKU from your script.

然后请确保您通过脚本传递不同的产品 SKU。

回答by Sathiya Raj

Run this sql query in your magento data base.

在您的 magento 数据库中运行此 sql 查询。

TRUNCATE dataflow_batch_export ;

TRUNCATE dataflow_batch_import ; 

TRUNCATE log_customer ; 

TRUNCATE log_quote ; 

TRUNCATE log_summary ; 

TRUNCATE log_summary_type ; 

TRUNCATE log_url ; 

TRUNCATE log_url_info ; 

TRUNCATE log_visitor ; 

TRUNCATE log_visitor_info ; 

TRUNCATE log_visitor_online ; 

TRUNCATE report_event ;

First you have to check the 'log_visitor_info' table structure. In this table 'visitor_id' field is should default value as null. If default value is set as anything you should run this below query, Otherwise you leave it the below query just execute the above query.

首先,您必须检查“log_visitor_info”表结构。在此表中,'visitor_id' 字段的默认值应为 null。如果默认值设置为任何你应该运行这个下面的查询,否则你留下下面的查询只执行上面的查询。

ALTER TABLE `log_visitor_info` CHANGE `visitor_id` `visitor_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'Visitor ID';

回答by Hazem Noor

This problem is because table log_visitor_infocontains extra rows of visitors that doesn't exist in log_visitortable, as explained in @creuzerm's comment;

这个问题是因为表中log_visitor_info包含表中不存在的额外访问者行log_visitor,如@creuzerm 的评论中所述;

if you run these queries you must have the same result

如果你运行这些查询,你必须有相同的结果

SELECT MAX(`visitor_id`) FROM `log_visitor`;

SELECT MAX(`visitor_id`) FROM `log_visitor_info`;

to solve this problem you need to delete these extra invalid rows with the following query

要解决此问题,您需要使用以下查询删除这些额外的无效行

DELETE FROM `log_visitor_info` WHERE `visitor_id` > ( SELECT MAX(`visitor_id`) FROM `log_visitor` );

for consistency run this too

为了一致性也运行这个

DELETE FROM `log_visitor_online` WHERE `visitor_id` > ( SELECT MAX(`visitor_id`) FROM `log_visitor` );