Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Magento类别产品重新索引错误_Php_Database_Magento - Fatal编程技术网

Php Magento类别产品重新索引错误

Php Magento类别产品重新索引错误,php,database,magento,Php,Database,Magento,我最近将magento从1.5升级到1.9,除了重新编制类别产品的索引外,其他一切都正常运行 在管理后端,我刚刚得到一个常规错误,进程失败 因此,我通过命令行使用shell/indexer.php完成了这项工作,结果如下: [www-data@DevServer shell]$ php -f indexer.php reindexall Product Attributes index was rebuilt successfully in 00:00:20 Product Prices ind

我最近将magento从1.5升级到1.9,除了重新编制类别产品的索引外,其他一切都正常运行

在管理后端,我刚刚得到一个常规错误,进程失败

因此,我通过命令行使用
shell/indexer.php
完成了这项工作,结果如下:

[www-data@DevServer shell]$ php -f indexer.php reindexall
Product Attributes index was rebuilt successfully in 00:00:20
Product Prices index was rebuilt successfully in 00:00:06
Catalog URL Rewrites index was rebuilt successfully in 00:02:59
Category Products index process unknown error:
exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`dev_salveo`.`catalog_category_product_index`, CONSTRAINT `FK_CAT_CTGR_PRD_IDX_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`category_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON )' in /home/www-data/dev.my-domain.co.uk/public_html/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /home/www-data/dev.my-domain.co.uk/public_html/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /home/www-data/dev.my-domain.co.uk/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /home/www-data/dev.my-domain.co.uk/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#4 /home/www-data/dev.my-domain.co.uk/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#5 /home/www-data/dev.my-domain.co.uk/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array)
#6 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(179): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...')
#7 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Resource/Helper/Mysql4.php(49): Mage_Index_Model_Resource_Abstract->insertFromSelect(Object(Varien_Db_Select), 'catalog_categor...', Array, false)
#8 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(153): Mage_Index_Model_Resource_Helper_Mysql4->insertData(Object(Mage_Catalog_Model_Resource_Category_Indexer_Product), Object(Varien_Db_Select), 'catalog_categor...', Array, false)
#9 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(113): Mage_Index_Model_Resource_Abstract->insertFromTable('catalog_categor...', 'catalog_categor...', false)
#10 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Catalog/Model/Resource/Category/Indexer/Product.php(935): Mage_Index_Model_Resource_Abstract->syncData()
#11 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Indexer/Abstract.php(143): Mage_Catalog_Model_Resource_Category_Indexer_Product->reindexAll()
#12 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Process.php(212): Mage_Index_Model_Indexer_Abstract->reindexAll()
#13 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Process.php(260): Mage_Index_Model_Process->reindexAll()
#14 /home/www-data/dev.my-domain.co.uk/public_html/shell/indexer.php(167): Mage_Index_Model_Process->reindexEverything()
#15 /home/www-data/dev.my-domain.co.uk/public_html/shell/indexer.php(215): Mage_Shell_Compiler->run()
#16 {main}

Next exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`dev_salveo`.`catalog_category_product_index`, CONSTRAINT `FK_CAT_CTGR_PRD_IDX_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`category_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON ), query was: INSERT INTO `catalog_category_product_index` (`category_id`, `product_id`, `position`, `is_parent`, `store_id`, `visibility`) SELECT `catalog_category_product_index_idx`.`category_id`, `catalog_category_product_index_idx`.`product_id`, `catalog_category_product_index_idx`.`position`, `catalog_category_product_index_idx`.`is_parent`, `catalog_category_product_index_idx`.`store_id`, `catalog_category_product_index_idx`.`visibility` FROM `catalog_category_product_index_idx` ON DUPLICATE KEY UPDATE `category_id` = VALUES(`category_id`), `product_id` = VALUES(`product_id`), `position` = VALUES(`position`), `is_parent` = VALUES(`is_parent`), `store_id` = VALUES(`store_id`), `visibility` = VALUES(`visibility`)' in /home/www-data/dev.my-domain.co.uk/public_html/lib/Zend/Db/Statement/Pdo.php:235
Stack trace:
#0 /home/www-data/dev.my-domain.co.uk/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /home/www-data/dev.my-domain.co.uk/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#3 /home/www-data/dev.my-domain.co.uk/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#4 /home/www-data/dev.my-domain.co.uk/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array)
#5 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(179): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...')
#6 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Resource/Helper/Mysql4.php(49): Mage_Index_Model_Resource_Abstract->insertFromSelect(Object(Varien_Db_Select), 'catalog_categor...', Array, false)
#7 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(153): Mage_Index_Model_Resource_Helper_Mysql4->insertData(Object(Mage_Catalog_Model_Resource_Category_Indexer_Product), Object(Varien_Db_Select), 'catalog_categor...', Array, false)
#8 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(113): Mage_Index_Model_Resource_Abstract->insertFromTable('catalog_categor...', 'catalog_categor...', false)
#9 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Catalog/Model/Resource/Category/Indexer/Product.php(935): Mage_Index_Model_Resource_Abstract->syncData()
#10 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Indexer/Abstract.php(143): Mage_Catalog_Model_Resource_Category_Indexer_Product->reindexAll()
#11 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Process.php(212): Mage_Index_Model_Indexer_Abstract->reindexAll()
#12 /home/www-data/dev.my-domain.co.uk/public_html/app/code/core/Mage/Index/Model/Process.php(260): Mage_Index_Model_Process->reindexAll()
#13 /home/www-data/dev.my-domain.co.uk/public_html/shell/indexer.php(167): Mage_Index_Model_Process->reindexEverything()
#14 /home/www-data/dev.my-domain.co.uk/public_html/shell/indexer.php(215): Mage_Shell_Compiler->run()
#15 {main}
Catalog Search Index index was rebuilt successfully in 00:00:24
Stock Status index was rebuilt successfully in 00:00:00
Tag Aggregation Data index was rebuilt successfully in 00:00:00

你知道这个错误是什么意思吗?如何修复它?

此错误是因为实体表中缺少类别id或产品id。 当尝试运行类别产品索引时,由于索引过程试图在目录\u类别\u产品\u索引表中插入一行,其中产品\u id或类别\u id不存在。这会导致“完整性约束冲突”

当从较低版本升级时数据库损坏时,有时会发生这种情况

使用以下函数更新表:

require_once 'abstract.php';
class Fix_Shell_Index_Table_Repair extends Mage_Shell_Abstract
{

    /**
     *
     * @return Varien_Db_Adapter_Interface
     */
    protected function _getConnection()
    {
        $resource = Mage::getSingleton('core/resource');
        $writeConnection = $resource->getConnection('core_write');
        return $writeConnection;
    }

    /**
     *Delete catalog product relation table data.
     */
    protected function _processTableData()
    {

        $this->_getConnection()->query('delete from `catalog_category_product` WHERE product_id not in(select entity_id from `catalog_product_entity`);');
        echo "catalog_category_product table repaired\n";

        $this->_getConnection()->query('delete from `catalog_category_product` WHERE category_id not in(select entity_id from catalog_category_entity); ');
        echo "catalog_category_product table repaired\n";

        $this->_getConnection()->query('delete from `catalog_product_website` WHERE product_id not in(select entity_id from catalog_product_entity); ');
        echo "catalog_product_website table repaired\n";

        $this->_getConnection()->query('delete from `catalog_product_index_eav_idx` WHERE entity_id not in(select entity_id from catalog_product_entity); ');
        echo "catalog_product_index_eav_idx table repaired\n";

        $this->_getConnection()->query('delete from `catalog_product_index_eav` WHERE entity_id not in(select entity_id from catalog_product_entity); ');
        echo "catalog_product_index_eav table repaired\n";

        $this->_getConnection()->query('delete from `catalog_product_link` WHERE product_id not in(select entity_id from catalog_product_entity); ');
        echo "catalog_product_link table repaired\n";

        $this->_getConnection()->query('delete from `catalog_product_relation` WHERE parent_id not in(select entity_id from catalog_product_entity);');
        echo "catalog_product_relation table repaired\n";

        $this->_getConnection()->query('DELETE from `sales_flat_quote_shipping_rate` WHERE `address_id` not in(select `address_id` from `sales_flat_quote_address`);');
        echo "sales_flat_quote_shipping_rate table repaired\n";

        echo "All done\n";
    }

    /**
     * Run script
     *
     * @return void
     */
    public function run()
    {
        try {
            $this->_processTableData();
        } catch (Exception $e) {
            echo $e->getMessage();
        }

    }
}

$shell = new Fix_Shell_Index_Table_Repair();
$shell->run();

此错误是因为实体表中缺少类别id或产品id。 当尝试运行类别产品索引时,由于索引过程试图在目录\u类别\u产品\u索引表中插入一行,其中产品\u id或类别\u id不存在。这会导致“完整性约束冲突”

当从较低版本升级时数据库损坏时,有时会发生这种情况

使用以下函数更新表:

require_once 'abstract.php';
class Fix_Shell_Index_Table_Repair extends Mage_Shell_Abstract
{

    /**
     *
     * @return Varien_Db_Adapter_Interface
     */
    protected function _getConnection()
    {
        $resource = Mage::getSingleton('core/resource');
        $writeConnection = $resource->getConnection('core_write');
        return $writeConnection;
    }

    /**
     *Delete catalog product relation table data.
     */
    protected function _processTableData()
    {

        $this->_getConnection()->query('delete from `catalog_category_product` WHERE product_id not in(select entity_id from `catalog_product_entity`);');
        echo "catalog_category_product table repaired\n";

        $this->_getConnection()->query('delete from `catalog_category_product` WHERE category_id not in(select entity_id from catalog_category_entity); ');
        echo "catalog_category_product table repaired\n";

        $this->_getConnection()->query('delete from `catalog_product_website` WHERE product_id not in(select entity_id from catalog_product_entity); ');
        echo "catalog_product_website table repaired\n";

        $this->_getConnection()->query('delete from `catalog_product_index_eav_idx` WHERE entity_id not in(select entity_id from catalog_product_entity); ');
        echo "catalog_product_index_eav_idx table repaired\n";

        $this->_getConnection()->query('delete from `catalog_product_index_eav` WHERE entity_id not in(select entity_id from catalog_product_entity); ');
        echo "catalog_product_index_eav table repaired\n";

        $this->_getConnection()->query('delete from `catalog_product_link` WHERE product_id not in(select entity_id from catalog_product_entity); ');
        echo "catalog_product_link table repaired\n";

        $this->_getConnection()->query('delete from `catalog_product_relation` WHERE parent_id not in(select entity_id from catalog_product_entity);');
        echo "catalog_product_relation table repaired\n";

        $this->_getConnection()->query('DELETE from `sales_flat_quote_shipping_rate` WHERE `address_id` not in(select `address_id` from `sales_flat_quote_address`);');
        echo "sales_flat_quote_shipping_rate table repaired\n";

        echo "All done\n";
    }

    /**
     * Run script
     *
     * @return void
     */
    public function run()
    {
        try {
            $this->_processTableData();
        } catch (Exception $e) {
            echo $e->getMessage();
        }

    }
}

$shell = new Fix_Shell_Index_Table_Repair();
$shell->run();
完全正确我在phpMyAdmin中运行了以下内容(取自您的答案),并将其重新索引:)当场!我在phpMyAdmin中运行了以下内容(取自您的答案),并将其重新索引:)