Magento:自写产品导入/更新后重建索引抛出异常
我们有一个模块可以将产品导入magento。该模块是由 Magento 程序员编写的。它使用 Magento API 并用 PHP 编写。它读取一个类似 CSV 的文件(实际使用的分隔符是“#”),将一行转换为一个乘积,然后将乘积写回 Magento。到目前为止,一切都很好。
我已经复制并更改了该模块几次。最后的更改是更新产品,而不是导入整个产品。该模块适用于大约 950 个这样的产品,然后抛出一个异常:
magento:/srv/www/vhosts/www.mysite.com/shell # php import_colors.php ../var/import/colors.csv.out.csv
PHP Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '12804-176-1-563' for key 'PRIMARY'' in /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement/Pdo.php:234
Stack trace:
#0 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Adapter/Abstract.php(468): Zend_Db_Statement->execute(Array)
#2 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#3 /srv/www/vhosts/www.mysite.com/lib/Varien/Db/Adapter/Pdo/Mysql.php(333): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array)
#4 /srv/www/vhosts/www.mysite.com/lib/Varien/Db/Adapter/Pdo/Mysql.php(1537): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...', Array)
#5 /srv/www/vhosts/www.mysite.com/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav in /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement/Pdo.php on line 234
Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '12804-176-1-563' for key 'PRIMARY'' in /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement/Pdo.php:234
Stack trace:
#0 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Adapter/Abstract.php(468): Zend_Db_Statement->execute(Array)
#2 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#3 /srv/www/vhosts/www.mysite.com/lib/Varien/Db/Adapter/Pdo/Mysql.php(333): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array)
#4 /srv/www/vhosts/www.mysite.com/lib/Varien/Db/Adapter/Pdo/Mysql.php(1537): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...', Array)
#5 /srv/www/vhosts/www.mysite.com/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav in /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement/Pdo.php on line 234
我没有想到它。客户很高兴自己更换了最后50个左右的产品,并且忘记了错误消息。
然而,今天客户打电话说他的产品属性索引无法建立,后台的索引仍然是橙色的“处理中”。于是我研究了一下,发现可以使用shell/indexer.php来建立索引。所以我尝试过,你瞧,我几乎忘记了完全相同的错误消息。
我已经转储了数据库并试图找出哪个表实际上包含错误消息(12804-176-1-563)中列出的数据,但我没有运气。貌似这4个日期按照这个顺序根本找不到。
现在,关于如何进行有两种选择。一种方法是找出哪个表实际上包含问题,以便可以使用 Magento 本身来修复它。另一种方法可能是清除相应的索引表并从头重建索引。我不确定在我不完全理解的数据库模式中进行挖掘是个好主意。
有人可以帮我找出问题所在吗?
we have a module to import products into magento. The module was written by a Magento programmer. It uses the Magento API and is written in PHP. It reads a CSV-like file (the actual delimiter used is '#'), translates a line into a product, then writes back the product to Magento. So far, so good.
I've duplicated and changed the module a few times. The last change was to update products, not import whole products. The module worked for about 950 of these products, then threw an exception:
magento:/srv/www/vhosts/www.mysite.com/shell # php import_colors.php ../var/import/colors.csv.out.csv
PHP Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '12804-176-1-563' for key 'PRIMARY'' in /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement/Pdo.php:234
Stack trace:
#0 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Adapter/Abstract.php(468): Zend_Db_Statement->execute(Array)
#2 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#3 /srv/www/vhosts/www.mysite.com/lib/Varien/Db/Adapter/Pdo/Mysql.php(333): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array)
#4 /srv/www/vhosts/www.mysite.com/lib/Varien/Db/Adapter/Pdo/Mysql.php(1537): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...', Array)
#5 /srv/www/vhosts/www.mysite.com/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav in /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement/Pdo.php on line 234
Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '12804-176-1-563' for key 'PRIMARY'' in /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement/Pdo.php:234
Stack trace:
#0 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Adapter/Abstract.php(468): Zend_Db_Statement->execute(Array)
#2 /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#3 /srv/www/vhosts/www.mysite.com/lib/Varien/Db/Adapter/Pdo/Mysql.php(333): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array)
#4 /srv/www/vhosts/www.mysite.com/lib/Varien/Db/Adapter/Pdo/Mysql.php(1537): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...', Array)
#5 /srv/www/vhosts/www.mysite.com/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav in /srv/www/vhosts/www.mysite.com/lib/Zend/Db/Statement/Pdo.php on line 234
I thought nothing of it. The customer was happily changing the last 50 or so products on his own, and the error message was forgotten.
However, today the customer called that his product attribute index would not build, the index in the backoffice remained on orange "Processing". So I've investigated and found out that the index can be built by using shell/indexer.php. So I've tried and, and lo and behold, the exact same error message I almost forgot.
I've dumped the database and tried to find out which table actually contained the data listed in the error message (12804-176-1-563), but I had no luck. It seems that these 4 dates are nowhere to be found in this order.
Now, there are two options on how to proceed. One would be to find out which table actually contains the problem, so that it might be fixed using Magento itself. The other way might be to clear the corresponding index table and rebuild the index from scratch. I'm not certain digging around in a database schema I do not fully understand is a good idea.
Can anybody help me identify the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请检查这不是简单的事情,例如数据库中的某些重复产品已被“中止”,从而留下没有 SKU 值的产品条目。
Please check that this is not something simple such as some duplicated products in the database that have been 'aborted' to leave a product entry with no SKU value.
我自己编写的 PHP 导入脚本也有同样的问题。我仍然不确定如何解决这个问题,但我发现在12804-176-1-563中,12804指的是数据库中产品的id。因此,如果您删除/重新创建或禁用该产品,那么索引器将正常工作。
如果您对为什么存在一些完整性约束违规有任何提示,请分享! :-)
I have the same issue with a self written PHP import script. I am still not sure how to fix this, but I found that in 12804-176-1-563, 12804 refers to the id of the product in the DB. So if you delete/recreate or disable that product, then the indexer will work fine will work fine.
If you have any tip on why there are some integrity constrain violations please share! :-)