[英]Magento - Order saving error: SQLSTATE[23000]: Integrity constraint violation
Sometimes, when we place an order in the backend - with a NEW customer, we get the following error upon submitting it: 有时,当我们在后端与新客户下订单时,在提交订单时会出现以下错误:
Order saving error: SQLSTATE[23000]: Integrity constraint violation: 1452
Cannot add or update a child row: a foreign key constraint fails
`artizara_artizara/enterprise_reward`, CONSTRAINT `FK_REWARD_CUSTOMER_ID`
FOREIGN KEY (`customer_id`) REFERENCES customer_entity` (`entity_id`)
ON DELETE CASCADE ON UPDATE CASCADE)
I've looked up the error log and it says the following: 我查找了错误日志,它显示以下内容:
exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint
violation: 1452 Cannot add or update a child row: a foreign key constraint fails
(`artizara_artizara/enterprise_reward`, CONSTRAINT `FK_REWARD_CUSTOMER_ID`
FOREIGN KEY (`customer_id`) REFERENCES `customer_entity` (`entity_id`) ON DELETE
CASCADE ON UPDATE CASCADE)' in /chroot/home/artizara/artizara.com/html/lib/Zend/Db/Statement/Pdo.php:228
I've researched this in google/Magento forums and some people say it has to do with the table not being InnobDB... 我已经在google / Magento论坛中对此进行了研究,有人说这与不是InnobDB的表有关...
So I went into phpMyAdmin and pulled up the enterprise_reward
table. 所以我进入phpMyAdmin并调出了enterprise_reward
表。 Opened the Operations tab. 打开操作选项卡。 Next to Storage Engine it says InnoDB so I think I'm set there... 在存储引擎旁边,它说InnoDB,所以我认为我已经在那里设置了...
Other people tried making sql statements for their issue by searching for orphan data. 其他人尝试通过搜索孤立数据来制作针对其问题的sql语句。 I'm not quite sure what this is looking for exactly so I don't know how to put the sql statement together (I'm a bit newer at that anyway). 我不确定这到底在寻找什么,所以我不知道如何将sql语句放在一起(无论如何我还是比较新的)。
Will someone please help figure this out (making by searching for the orphan data, etc) and perhaps let me know why this has happened in the first place? 有人可以帮忙弄清楚这一点(通过搜索孤儿数据等),也许让我知道为什么会首先发生?
FYI - they can't give me a clear picture as to whether this happens with EVERY new customer (when placing an order in the admin) or just sometimes - so I don't have that info (yet)... 仅供参考-他们无法给我清晰的图片说明这是发生在每个新客户(在管理员下订单时)还是仅在某些情况下发生-所以我没有该信息(尚未)...
Edit 5/16 @ 2:30p: 编辑5/16 @ 2:30p:
I've tried looking for orphans with this sql code but no results returned ... 我尝试用此sql代码寻找孤儿,但未返回任何结果 ...
SELECT
*
FROM
enterprise_reward
LEFT
JOIN
customer_entity
ON enterprise_reward.customer_id = customer_entity.entity_id
WHERE
customer_entity.entity_id IS NULL
We are indeed experiencing this same issue on enterprise 1.10.0.1. 我们确实在企业1.10.0.1。上遇到了同样的问题。 This appears to be a known bug that has been filed with Varien. 这似乎是Varien提交的已知错误。 However - I have not found a solution. 但是-我没有找到解决方案。
Best thing I could find is this thread: http://www.magentocommerce.com/boards/v/viewthread/234872 我能找到的最好的东西是这个线程: http : //www.magentocommerce.com/boards/v/viewthread/234872
The bug report I found is posted below. 我发现的错误报告发布在下面。
BUG ID: 26516 Posted: 2011-09-21 15:22:18 错误的ID:26516发表:2011-09-21 15:22:18
When payment processing fails with an exception, the following error occurs in certain situations: 当付款处理因异常而失败时,在某些情况下会发生以下错误:
Zend_Db_Statement_Exception: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
magento_enterprise
.enterprise_reward
, CONSTRAINTFK_REWARD_CUSTOMER_ID
FOREIGN KEY (customer_id
) REFERENCEScustomer_entity
(entity_id
) ON DELETE CASCADE ON UPDATE CASCADE) Zend_Db_Statement_Exception:SQLSTATE [23000]:完整性约束违规:1452不能添加或更新子行(外键约束失败magento_enterprise
。enterprise_reward
,约束FK_REWARD_CUSTOMER_ID
外键(customer_id
)参考customer_entity
(entity_id
)ON DELETE CASCADE ON UPDATE CASCADE)
./lib/Zend/Db/Statement/Pdo.php:234
./lib/Zend/Db/Statement.php:300
./lib/Zend/Db/Adapter/Abstract.php:479
./lib/Zend/Db/Adapter/Pdo/Abstract.php:238
./lib/Varien/Db/Adapter/Pdo/Mysql.php:333
./lib/Zend/Db/Adapter/Abstract.php:574
./app/code/core/Mage/Core/Model/Mysql4/Abstract.php:414
./app/code/core/Mage/Core/Model/Abstract.php:318
./app/code/core/Enterprise/Reward/Model/Reward.php:202
./app/code/core/Enterprise/Reward/Model/Observer.php:548
./app/code/core/Enterprise/Reward/Model/Observer.php:564
./app/code/core/Mage/Core/Model/App.php:1265
./app/code/core/Mage/Core/Model/App.php:1246
./app/Mage.php:416
./app/code/core/Mage/Sales/Model/Service/Quote.php:187
./app/code/core/Mage/Sales/Model/Service/Quote.php:126
./EnterpriseRewardTest.php:70
Steps to reproduce: 重现步骤:
I attached a PHPUnit test case that should reproduce the problem reliably. 我附加了一个PHPUnit测试用例,该用例应该可以可靠地重现该问题。
The culprit is the code in Mage_Sales_Model_Service_Quote::submitOrder that does the following: 罪魁祸首是执行以下操作的Mage_Sales_Model_Service_Quote :: submitOrder中的代码:
Now, if a handler for quote_submit_failure proceeds to use order's customerId, it will necessarily trigger the aforementioned "integrity constraint violation" error. 现在,如果quote_submit_failure的处理程序继续使用订单的customerId,它将必然触发上述“完整性约束违规”错误。
The problem can be reproduced on following versions: - Magento Enterprise Edition v1.10.0.1 - Magento Community Edition v1.6.0.0 (provided there happens to be a quote_submit_failure handler that expect a valid customerId. 可以在以下版本上重现该问题:-Magento企业版v1.10.0.1-Magento社区版v1.6.0.0(前提是碰巧有一个quote_submit_failure处理程序期望有效的customerId。
You can also add $this->_stmt->queryString to Zend_Db_Statement_Exception at lib/Zend/Db/Statement/Pdo.php (_execute method) to see what query is throwing the error. 您还可以在lib / Zend / Db / Statement / Pdo.php(_execute方法)将$ this- > _ stmt-> queryString添加到Zend_Db_Statement_Exception(_execute方法),以查看引发该错误的查询。
It will be something like.. 会像..
throw new Zend_Db_Statement_Exception($e->getMessage() . $this->_stmt->queryString, (int) $e->getCode(), $e);
But remember: do not commit core modifications in Magento. 但请记住:不要在Magento中进行核心修改。 It's not cool. 不酷
Source: Aftab Naveed's Blog 资料来源: Aftab Naveed的博客
If using 1.10.0.1 or less, patch this file app/code/core/Enterprise/Reward/Model/Observer.php
by adding a check for customer id 如果使用1.10.0.1或更低版本,请通过添加对客户ID的检查来修补此文件app/code/core/Enterprise/Reward/Model/Observer.php
protected function _revertRewardPointsForOrder(Mage_Sales_Model_Order $order)
{
// Patch for known 1.10.0.1 bug
if (!$order->getCustomer()->getId()) {
return $this;
}
// End patch
Mage::getModel('enterprise_reward/reward')
->setCustomerId($order->getCustomerId())
->setWebsiteId(Mage::app()->getStore($order->getStoreId())->getWebsiteId())
->setPointsDelta($order->getRewardPointsBalance())
->setAction(Enterprise_Reward_Model_Reward::REWARD_ACTION_REVERT)
->setActionEntity($order)
->updateRewardPoints();
return $this;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.