0
votes

I have an error when I try to reindex Magento 1.7 catalog product flat index (through admin panel or command line).

On the command line I get the following error:

Product Flat Data index process unknown error:
exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1005
Can't create table 'databasename.#sql-340a_22a3' (errno: 121)' in
/var/www/clients/client1/web16/web/lib/Zend/Db/Statement/Pdo.php:228

When I look in mysql using 'SHOW ENGINE INNODB STATUS;', I get the following error:

160830 10:17:09 Error in foreign key constraint creation for table
`databasename`.`#sql-340a_2160`.
A foreign key constraint of name 
`databasename`.`FK_MAGE_MAGE_CAT_PRD_FLAT_1_ENTT_ID_MAGE_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.

Any idea how to fix this?

2
I'm voting to close this question as off-topic because Stack Overflow is a programming-related Q&A site. Your question is not about programming. Perhaps you should post it on magento.stackexchange.com instead? - Enigmativity

2 Answers

0
votes

Disable foreign_key_checks MySQL option before reindex

SET foreign_key_checks = 0;
// job
SET foreign_key_checks = 1;
0
votes

I don't think that disabling foreign key checks is a good idea as it can lead to corrupted lines. In fact, this error is the result of some corrupted lines already.

You may read this thread which is, to me, a better way to resolve this issue: https://magento.stackexchange.com/questions/9974/product-flat-data-wont-reindex/354240