Magento重建索引问题 - 一般错误:1005无法创建表(错误号:121)

时间:2014-12-15 15:21:05

标签: mysql magento

我无法在生产服务器上重新索引Product Flat Data,而我正在使用以下命令。

nohup php -f indexer.php -- --reindex catalog_product_flat &

错误消息是:

Next exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[HY000]: General error: 1005 Can't create table 'database_name.catalog_product_flat_2' (errno: 121)' in /home/corecolu/public_html/lib/Zend/Db/Statement/Pdo.php:234
Stack trace:
#0 /home/corecolu/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/corecolu/public_html/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /home/corecolu/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 /home/corecolu/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('CREATE TABLE `c...', Array)
#4 /home/corecolu/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(389): Zend_Db_Adapter_Pdo_Abstract->query('CREATE TABLE `c...', Array)
#5 /home/corecolu/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(2018): Varien_Db_Adapter_Pdo_Mysql->query('CREATE TABLE `c...')
#6 /home/corecolu/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(702): Varien_Db_Adapter_Pdo_Mysql->createTable(Object(Varien_Db_Ddl_Table))
#7 /home/corecolu/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(1390): Mage_Catalog_Model_Resource_Product_Flat_Indexer->prepareFlatTable(2)
#8 /home/corecolu/public_html/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php(296): Mage_Catalog_Model_Resource_Product_Flat_Indexer->reindexAll()
#9 /home/corecolu/public_html/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php(336): Mage_Catalog_Model_Product_Flat_Indexer->reindexAll()
#10 /home/corecolu/public_html/app/code/core/Mage/Index/Model/Process.php(207): Mage_Catalog_Model_Product_Indexer_Flat->reindexAll()
#11 /home/corecolu/public_html/app/code/core/Mage/Index/Model/Process.php(253): Mage_Index_Model_Process->reindexAll()
#12 /home/corecolu/public_html/shell/indexer.php(158): Mage_Index_Model_Process->reindexEverything()
#13 /home/corecolu/public_html/shell/indexer.php(198): Mage_Shell_Compiler->run()
#14 {main}

我尝试截断并删除表(4个平表),但他们没有工作。索引过程可以成功创建和索引两个平面表(_flat_1和_flat_3),它总是卡在catalog_product_flat_2上。但是,如果我将相同的数据库放入开发服务器,然后截断或删除平​​面表,则重建索引工作正常。

我认为这是innodb状态的相关错误:

------------------------
LATEST FOREIGN KEY ERROR
------------------------
141214 20:48:16 Error in foreign key constraint creation for table `database_name`.`catalog_product_flat_2`.
A foreign key constraint of name `database_name`.`FK_CAT_PRD_FLAT_2_ENTT_ID_CAT_PRD_ENTT_ENTT_ID`
already exists. (Note that internally InnoDB adds 'databasename'
in front of the user-defined constraint name.)
Note that InnoDB's FOREIGN KEY system tables store
constraint names as case-insensitive, with the
MySQL standard latin1_swedish_ci collation. If you
create tables or databases whose names differ only in
the character case, then collisions in constraint
names can occur. Workaround: name your constraints
explicitly with unique names.

我对此问题表示感谢。

2 个答案:

答案 0 :(得分:1)

几个星期前,我遇到了同样的问题 - 没有任何理由将所有表格都更改为MyISAM,之后我得到了与你相同的错误。 Magento严格要求InnoDB(外键和交易)。在我为所有表更改引擎后问题得以解决。

http://www.magentocommerce.com/wiki/groups/227/convert_database_to_innodb

答案 1 :(得分:0)

您需要检查您的架构FK_CAT_PRD_FLAT_2_ENTT_ID_CAT_PRD_ENTT_ENTT_ID id此键已经定义。 还要检查可能具有自定义目录平板产品索引的核心文件或模块。可能在索引代码中有一些修改导致类似的键约束创建两次。