Magento错误:消息'SQLSTATE [23000]的异常'PDOException'

时间:2013-12-06 15:40:25

标签: xml database magento foreign-keys

尝试从XML文件上传产品时,我从Magento收到以下错误:

  

阵列(       [id] => 1       [filename] => /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/temp/xmlimport/Alpha_price_046551_01.xml       [processed] => 0       [adddate] => 1386340077)记录数:1000个异常'PDOException',消息'SQLSTATE [23000]:完整性约束   违规:1452无法添加或更新子行:外键   约束失败(db23517_TestMagento/catalog_category_product,   约束FK_CAT_CTGR_PRD_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID外键   (category_id)参考catalog_category_entityentity_id)ON   DEL)'in   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/lib/3rdparty/Zend/Db/Statement/Pdo.php:228   堆栈跟踪:#0   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/lib/3rdparty/Zend/Db/Statement/Pdo.php(228):   PDOStatement->执行(数组)#1   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/lib/3rdparty/Zend/Db/Statement.php(320):   Zend_Db_Statement_Pdo-> _execute(Array)#2   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/lib/3rdparty/Zend/Db/Adapter/Abstract.php(468):   Zend_Db_Statement->执行(数组)#3   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/lib/3rdparty/Zend/Db/Adapter/Pdo/Abstract.php(238):   Zend_Db_Adapter_Abstract-> query('INSERT INTO ca...', Array) #4 /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/lib/3rdparty/Zend/Db/Adapter/Abstract.php(546): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO ca ...',数组)#5   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/models/productsModel.php(818):   Zend_Db_Adapter_Abstract-> insert('catalog_categor ...',Array)#6   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/import2.php(461):   ProductsModel-> updateProduct(Array,NULL,Array)#7 {main}接下来   异常'Zend_Db_Statement_Exception',消息'SQLSTATE [23000]:   完整性约束违规:1452无法添加或更新子行:   外键约束失败   (db23517_TestMagento/catalog_category_product,CONSTRAINT   FK_CAT_CTGR_PRD_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID外国钥匙   (category_id)参考catalog_category_entityentity_id)ON   DEL)'in   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/lib/3rdparty/Zend/Db/Statement/Pdo.php:234   堆栈跟踪:#0   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/lib/3rdparty/Zend/Db/Statement.php(320):   Zend_Db_Statement_Pdo-> _execute(Array)#1   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/lib/3rdparty/Zend/Db/Adapter/Abstract.php(468):   Zend_Db_Statement->执行(数组)#2   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/lib/3rdparty/Zend/Db/Adapter/Pdo/Abstract.php(238):   Zend_Db_Adapter_Abstract->查询('INSERT INTO ca...', Array) #3 /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/lib/3rdparty/Zend/Db/Adapter/Abstract.php(546): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO ca ...',数组)#4   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/models/productsModel.php(818):   Zend_Db_Adapter_Abstract-> insert('catalog_categor ...',Array)#5   /var/www/vhosts/8/120463/webspace/httpdocs/casesupply.nl/importer/import2.php(461):   ProductsModel-> updateProduct(Array,NULL,Array)#6 {main}

每晚都会有一个XML文件更新我的所有产品,但最近我发现有些产品没有正确上传。所以我删除了数据库中的所有产品。我用了一个脚本。现在我想重新上载XML文件中的所有产品,但我不断收到此错误消息。希望有人可以帮助我解决这个问题。

2 个答案:

答案 0 :(得分:0)

错误很明显,您正在尝试将实体字段更新为引用表中不存在的值(我猜测为category_entity表)在运行查询之前检查引用表中是否存在所有类别记录,你可以试试这个

答案 1 :(得分:0)

我认为这意味着您正在尝试插入数据库认为已经存在的记录。错误代码告诉你你要插入的记录必须是独一无二的。

我建议您检查XML文件是否有重复项,并确保数据库中已存在XML文件中的任何内容。