0

有时,当我们在后端下订单时 - 对于新客户,我们在提交时收到以下错误:

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)

我查看了错误日志,它显示以下内容:

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

我在 google/Magento 论坛中对此进行了研究,有些人说这与表格不是 InnobDB 有关...

所以我进入 phpMyAdmin 并拉起enterprise_reward桌子。打开操作选项卡。在存储引擎旁边它说 InnoDB 所以我想我已经设置好了......

其他人尝试通过搜索孤立数据来为他们的问题制作 sql 语句。我不太确定这到底在寻找什么,所以我不知道如何将 sql 语句放在一起(无论如何我都比较新)。

有人会帮助解决这个问题(通过搜索孤儿数据等),也许让我知道为什么会发生这种情况?

仅供参考 - 他们无法让我清楚地了解每个新客户是否会发生这种情况(在管理员中下订单时)或只是有时 - 所以我没有那个信息(还)......

编辑 5/16 @ 2:30p:

我试过用这个 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
4

3 回答 3

0

We are indeed experiencing this same issue on enterprise 1.10.0.1. This appears to be a known bug that has been filed with Varien. However - I have not found a solution.

Best thing I could find is this thread: 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

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, CONSTRAINT FK_REWARD_CUSTOMER_ID FOREIGN KEY (customer_id) REFERENCES 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:

  • use Magento Enterprise with Enterprise Rewards enabled (or another module with a similar code, see below)
  • use a payment module that supports on-line authorization
  • check out an order as a new customer
  • trigger a payment error (e.g. by entering an invalid CC no).

I attached a PHPUnit test case that should reproduce the problem reliably.

The culprit is the code in Mage_Sales_Model_Service_Quote::submitOrder that does the following:

  1. start a transaction
  2. build a new order
  3. create a new customer and fill in the order's customerId field
  4. attempt to process the order, which raises an exception
  5. roll back the transaction
  6. dispatch "quote_submit_failure" event using the order as event data. Note that the order's customerId field now contains an invalid value since the transaction has been rolled back.

Now, if a handler for quote_submit_failure proceeds to use order's customerId, it will necessarily trigger the aforementioned "integrity constraint violation" error.

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.

于 2012-12-10T05:24:28.907 回答
0

您还可以在 lib/Zend/Db/Statement/Pdo.php (_execute 方法)中将$this->_stmt->queryString添加到 Zend_Db_Statement_Exception 以查看引发错误的查询。

它会像..

throw new Zend_Db_Statement_Exception($e->getMessage() . $this->_stmt->queryString, (int) $e->getCode(), $e);

但请记住:不要在 Magento 中提交核心修改。这不酷。

资料来源:Aftab Naveed 的博客

于 2013-04-19T14:23:35.560 回答
0

如果使用 1.10.0.1 或更低版本,app/code/core/Enterprise/Reward/Model/Observer.php请通过添加对客户 ID 的检查来修补此文件

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;
}
于 2013-05-07T18:28:47.910 回答