Mysql Magento重新编制索引问题-一般错误:1005 Can';t创建表(错误号:121)

Mysql Magento重新编制索引问题-一般错误:1005 Can';t创建表(错误号:121),mysql,magento,Mysql,Magento,我无法在生产服务器上重新索引产品平面数据,我正在使用以下命令 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_

我无法在生产服务器上重新索引产品平面数据,我正在使用以下命令

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),并且它总是卡在
目录产品\u flat_2
上。但是,如果我将同一个数据库放入development server,然后截断或删除平面表,则重新索引工作正常

我认为这是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.

非常感谢您在这个问题上提供的帮助。

您需要检查您的模式FK_CAT_PRD_FLAT_2_ENTT_ID_CAT_PRD_ENTT_ENTT_ID此密钥已定义。
另外,请检查可能已自定义目录平面产品索引的核心文件或模块。可能索引代码中有一些修改,导致两次创建类似的键约束。

几周前,我遇到了相同的问题-所有表都被更改为MyISAM,之后我得到了与以前相同的错误你。Magento严格要求InnoDB(外键和事务)。在我更换了所有表的引擎后,问题就解决了


请您详细说明我如何检查是否已定义了该项?你是说表格约束吗?如果是这样,它就不存在了。此网站没有任何可自定义索引的模块或代码。在您开始索引之前,或在索引开始创建两次时,上述约束已经存在,因此第二次将失败。使用外键约束提取数据的架构并检查导出的数据库;模式中存在平面1表约束和平面3表约束,它们应该是这样的。平面2约束不存在。我在另一个地方读到,另一个相同的mysql和非magento问题通过将数据库导出并导入到新的数据库名称中得到解决。这是另一种尝试方式。是的,数据库表可能存在一些问题。因此,如果通过导出从现有数据库创建新数据库,然后导入,则可能会对其进行排序。我们的表没有更改为MyISAM