Magento indexing is failing, SQLSTATE[23000]: Integrity constraint violation The Next CEO of Stack OverflowCan't re-index Category Products - SQLSTATE[23000]: Integrity constraint violation: 1452Magento 1.8 reindex allFix error “There was a problem with reindexing process.” or “Cannot initialize the indexer process.”Index Management ProblemProduct Attributes could not be reindexedSQLSTATE[42S02]: Base table or view not found: 1146 Table 'core_store' doesn't existReindex catalog categories url issueError when moving Magento File to a different domainSQLSTATE[HY000] : General error: 2013 Lost connection to MySQL server during query in MagentoInvalid method Yoast_MetaRobots_Block_Catalog_Product_View:MySQL cron_schedule update problem

Rotate a column

Customer Requests (Sometimes) Drive Me Bonkers!

If I blow insulation everywhere in my attic except the door trap, will heat escape through it?

Anatomically Correct Strange Women In Ponds Distributing Swords

What is the point of a new vote on May's deal when the indicative votes suggest she will not win?

Describing a person. What needs to be mentioned?

How to start emacs in "nothing" mode (`fundamental-mode`)

MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

How to write papers efficiently when English isn't my first language?

Grabbing quick drinks

Why did we only see the N-1 starfighters in one film?

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

Can the Reverse Gravity spell affect the Meteor Swarm spell?

Are there languages with no euphemisms?

What does this shorthand mean?

How long to clear the 'suck zone' of a turbofan after start is initiated?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

Why were Madagascar and New Zealand discovered so late?

Return the Closest Prime Number

How do I solve this limit?

How do I construct this japanese bowl?

Why do professional authors make "consistency" mistakes? And how to avoid them?

How should I support this large drywall patch?



Magento indexing is failing, SQLSTATE[23000]: Integrity constraint violation



The Next CEO of Stack OverflowCan't re-index Category Products - SQLSTATE[23000]: Integrity constraint violation: 1452Magento 1.8 reindex allFix error “There was a problem with reindexing process.” or “Cannot initialize the indexer process.”Index Management ProblemProduct Attributes could not be reindexedSQLSTATE[42S02]: Base table or view not found: 1146 Table 'core_store' doesn't existReindex catalog categories url issueError when moving Magento File to a different domainSQLSTATE[HY000] : General error: 2013 Lost connection to MySQL server during query in MagentoInvalid method Yoast_MetaRobots_Block_Catalog_Product_View:MySQL cron_schedule update problem










3















For some reason Magento indexing is failing, we haven't changed anything in the website.... And that is the weird thing! The error in shell using indexer.php:



$ php indexer.php --reindex catalog_product_flat
Product Flat Data 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 (`**********_db`.`#sql-649_47012`, CONSTRAINT `FK_CAT_PRD_FLAT_1_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON U)' in /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('ALTER TABLE `ca...', Array)
#5 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query('ALTER TABLE `ca...', Array)
#6 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(340): Varien_Db_Adapter_Pdo_Mysql->query('ALTER TABLE `ca...')
#7 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(2569): Varien_Db_Adapter_Pdo_Mysql->raw_query('ALTER TABLE `ca...')
#8 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(816): Varien_Db_Adapter_Pdo_Mysql->addForeignKey('FK_CAT_PRD_FLAT...', 'catalog_product...', 'entity_id', 'catalog_product...', 'entity_id', 'CASCADE', 'CASCADE')
#9 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(1390): Mage_Catalog_Model_Resource_Product_Flat_Indexer->prepareFlatTable(1)
#10 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php(296): Mage_Catalog_Model_Resource_Product_Flat_Indexer->reindexAll()
#11 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php(336): Mage_Catalog_Model_Product_Flat_Indexer->reindexAll()
#12 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Index/Model/Process.php(209): Mage_Catalog_Model_Product_Indexer_Flat->reindexAll()
#13 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Index/Model/Process.php(255): Mage_Index_Model_Process->reindexAll()
#14 /home/**********/domains/***********nna.nl/public_html/shell/indexer.php(160): Mage_Index_Model_Process->reindexEverything()
#15 /home/**********/domains/***********nna.nl/public_html/shell/indexer.php(200): Mage_Shell_Compiler->run()
#16 main









share|improve this question
























  • Check my answer on this link magento.stackexchange.com/questions/105393/… Hope this will help you

    – Asish Hira
    Mar 14 '16 at 7:27















3















For some reason Magento indexing is failing, we haven't changed anything in the website.... And that is the weird thing! The error in shell using indexer.php:



$ php indexer.php --reindex catalog_product_flat
Product Flat Data 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 (`**********_db`.`#sql-649_47012`, CONSTRAINT `FK_CAT_PRD_FLAT_1_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON U)' in /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('ALTER TABLE `ca...', Array)
#5 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query('ALTER TABLE `ca...', Array)
#6 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(340): Varien_Db_Adapter_Pdo_Mysql->query('ALTER TABLE `ca...')
#7 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(2569): Varien_Db_Adapter_Pdo_Mysql->raw_query('ALTER TABLE `ca...')
#8 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(816): Varien_Db_Adapter_Pdo_Mysql->addForeignKey('FK_CAT_PRD_FLAT...', 'catalog_product...', 'entity_id', 'catalog_product...', 'entity_id', 'CASCADE', 'CASCADE')
#9 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(1390): Mage_Catalog_Model_Resource_Product_Flat_Indexer->prepareFlatTable(1)
#10 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php(296): Mage_Catalog_Model_Resource_Product_Flat_Indexer->reindexAll()
#11 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php(336): Mage_Catalog_Model_Product_Flat_Indexer->reindexAll()
#12 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Index/Model/Process.php(209): Mage_Catalog_Model_Product_Indexer_Flat->reindexAll()
#13 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Index/Model/Process.php(255): Mage_Index_Model_Process->reindexAll()
#14 /home/**********/domains/***********nna.nl/public_html/shell/indexer.php(160): Mage_Index_Model_Process->reindexEverything()
#15 /home/**********/domains/***********nna.nl/public_html/shell/indexer.php(200): Mage_Shell_Compiler->run()
#16 main









share|improve this question
























  • Check my answer on this link magento.stackexchange.com/questions/105393/… Hope this will help you

    – Asish Hira
    Mar 14 '16 at 7:27













3












3








3


1






For some reason Magento indexing is failing, we haven't changed anything in the website.... And that is the weird thing! The error in shell using indexer.php:



$ php indexer.php --reindex catalog_product_flat
Product Flat Data 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 (`**********_db`.`#sql-649_47012`, CONSTRAINT `FK_CAT_PRD_FLAT_1_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON U)' in /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('ALTER TABLE `ca...', Array)
#5 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query('ALTER TABLE `ca...', Array)
#6 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(340): Varien_Db_Adapter_Pdo_Mysql->query('ALTER TABLE `ca...')
#7 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(2569): Varien_Db_Adapter_Pdo_Mysql->raw_query('ALTER TABLE `ca...')
#8 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(816): Varien_Db_Adapter_Pdo_Mysql->addForeignKey('FK_CAT_PRD_FLAT...', 'catalog_product...', 'entity_id', 'catalog_product...', 'entity_id', 'CASCADE', 'CASCADE')
#9 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(1390): Mage_Catalog_Model_Resource_Product_Flat_Indexer->prepareFlatTable(1)
#10 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php(296): Mage_Catalog_Model_Resource_Product_Flat_Indexer->reindexAll()
#11 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php(336): Mage_Catalog_Model_Product_Flat_Indexer->reindexAll()
#12 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Index/Model/Process.php(209): Mage_Catalog_Model_Product_Indexer_Flat->reindexAll()
#13 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Index/Model/Process.php(255): Mage_Index_Model_Process->reindexAll()
#14 /home/**********/domains/***********nna.nl/public_html/shell/indexer.php(160): Mage_Index_Model_Process->reindexEverything()
#15 /home/**********/domains/***********nna.nl/public_html/shell/indexer.php(200): Mage_Shell_Compiler->run()
#16 main









share|improve this question
















For some reason Magento indexing is failing, we haven't changed anything in the website.... And that is the weird thing! The error in shell using indexer.php:



$ php indexer.php --reindex catalog_product_flat
Product Flat Data 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 (`**********_db`.`#sql-649_47012`, CONSTRAINT `FK_CAT_PRD_FLAT_1_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON U)' in /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /home/**********/domains/***********nna.nl/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('ALTER TABLE `ca...', Array)
#5 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query('ALTER TABLE `ca...', Array)
#6 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(340): Varien_Db_Adapter_Pdo_Mysql->query('ALTER TABLE `ca...')
#7 /home/**********/domains/***********nna.nl/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(2569): Varien_Db_Adapter_Pdo_Mysql->raw_query('ALTER TABLE `ca...')
#8 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(816): Varien_Db_Adapter_Pdo_Mysql->addForeignKey('FK_CAT_PRD_FLAT...', 'catalog_product...', 'entity_id', 'catalog_product...', 'entity_id', 'CASCADE', 'CASCADE')
#9 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(1390): Mage_Catalog_Model_Resource_Product_Flat_Indexer->prepareFlatTable(1)
#10 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php(296): Mage_Catalog_Model_Resource_Product_Flat_Indexer->reindexAll()
#11 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php(336): Mage_Catalog_Model_Product_Flat_Indexer->reindexAll()
#12 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Index/Model/Process.php(209): Mage_Catalog_Model_Product_Indexer_Flat->reindexAll()
#13 /home/**********/domains/***********nna.nl/public_html/app/code/core/Mage/Index/Model/Process.php(255): Mage_Index_Model_Process->reindexAll()
#14 /home/**********/domains/***********nna.nl/public_html/shell/indexer.php(160): Mage_Index_Model_Process->reindexEverything()
#15 /home/**********/domains/***********nna.nl/public_html/shell/indexer.php(200): Mage_Shell_Compiler->run()
#16 main






magento-1.7 indexing sql reindex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 21 mins ago









Teja Bhagavan Kollepara

3,01241949




3,01241949










asked Jan 8 '15 at 9:56









xviloxvilo

1519




1519












  • Check my answer on this link magento.stackexchange.com/questions/105393/… Hope this will help you

    – Asish Hira
    Mar 14 '16 at 7:27

















  • Check my answer on this link magento.stackexchange.com/questions/105393/… Hope this will help you

    – Asish Hira
    Mar 14 '16 at 7:27
















Check my answer on this link magento.stackexchange.com/questions/105393/… Hope this will help you

– Asish Hira
Mar 14 '16 at 7:27





Check my answer on this link magento.stackexchange.com/questions/105393/… Hope this will help you

– Asish Hira
Mar 14 '16 at 7:27










2 Answers
2






active

oldest

votes


















7














it seams that you have zombie data in the flat table for store with id 1.

The prepareFlatTable method is trying to add a Foreign Key to the catalog_product_entity table and that fails.

Most probably because you already have in the catalog_product_flat_store_1 table a product id that is not in the catalog_product_entity table.



First backup your database (or at least catalog_product_flat_store_1 table), then truncate the table catalog_product_flat_store_1.



Or you can disable the usage of the flat catalog, remove the tables catalog_product_flat_store_*, re run the indexing then enable the usage of flat tables again.






share|improve this answer























  • i only have a table called catalog_product_flat_1, could that be the same?

    – xvilo
    Jan 8 '15 at 12:59











  • yes. I assume you have only one store view in your instance. the 1 at the end is the store view id. Magento creates one flat table for each store view.

    – Marius
    Jan 8 '15 at 13:46











  • Yes, Thank you for this answer, couldn't find the right one on the interwebs

    – xvilo
    Jan 8 '15 at 16:01


















-1














I have 4 languages so i truncated 4 tables.
catalog_product_flat_1, 2, 3, 4





share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f51536%2fmagento-indexing-is-failing-sqlstate23000-integrity-constraint-violation%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7














    it seams that you have zombie data in the flat table for store with id 1.

    The prepareFlatTable method is trying to add a Foreign Key to the catalog_product_entity table and that fails.

    Most probably because you already have in the catalog_product_flat_store_1 table a product id that is not in the catalog_product_entity table.



    First backup your database (or at least catalog_product_flat_store_1 table), then truncate the table catalog_product_flat_store_1.



    Or you can disable the usage of the flat catalog, remove the tables catalog_product_flat_store_*, re run the indexing then enable the usage of flat tables again.






    share|improve this answer























    • i only have a table called catalog_product_flat_1, could that be the same?

      – xvilo
      Jan 8 '15 at 12:59











    • yes. I assume you have only one store view in your instance. the 1 at the end is the store view id. Magento creates one flat table for each store view.

      – Marius
      Jan 8 '15 at 13:46











    • Yes, Thank you for this answer, couldn't find the right one on the interwebs

      – xvilo
      Jan 8 '15 at 16:01















    7














    it seams that you have zombie data in the flat table for store with id 1.

    The prepareFlatTable method is trying to add a Foreign Key to the catalog_product_entity table and that fails.

    Most probably because you already have in the catalog_product_flat_store_1 table a product id that is not in the catalog_product_entity table.



    First backup your database (or at least catalog_product_flat_store_1 table), then truncate the table catalog_product_flat_store_1.



    Or you can disable the usage of the flat catalog, remove the tables catalog_product_flat_store_*, re run the indexing then enable the usage of flat tables again.






    share|improve this answer























    • i only have a table called catalog_product_flat_1, could that be the same?

      – xvilo
      Jan 8 '15 at 12:59











    • yes. I assume you have only one store view in your instance. the 1 at the end is the store view id. Magento creates one flat table for each store view.

      – Marius
      Jan 8 '15 at 13:46











    • Yes, Thank you for this answer, couldn't find the right one on the interwebs

      – xvilo
      Jan 8 '15 at 16:01













    7












    7








    7







    it seams that you have zombie data in the flat table for store with id 1.

    The prepareFlatTable method is trying to add a Foreign Key to the catalog_product_entity table and that fails.

    Most probably because you already have in the catalog_product_flat_store_1 table a product id that is not in the catalog_product_entity table.



    First backup your database (or at least catalog_product_flat_store_1 table), then truncate the table catalog_product_flat_store_1.



    Or you can disable the usage of the flat catalog, remove the tables catalog_product_flat_store_*, re run the indexing then enable the usage of flat tables again.






    share|improve this answer













    it seams that you have zombie data in the flat table for store with id 1.

    The prepareFlatTable method is trying to add a Foreign Key to the catalog_product_entity table and that fails.

    Most probably because you already have in the catalog_product_flat_store_1 table a product id that is not in the catalog_product_entity table.



    First backup your database (or at least catalog_product_flat_store_1 table), then truncate the table catalog_product_flat_store_1.



    Or you can disable the usage of the flat catalog, remove the tables catalog_product_flat_store_*, re run the indexing then enable the usage of flat tables again.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 8 '15 at 10:01









    MariusMarius

    167k28319686




    167k28319686












    • i only have a table called catalog_product_flat_1, could that be the same?

      – xvilo
      Jan 8 '15 at 12:59











    • yes. I assume you have only one store view in your instance. the 1 at the end is the store view id. Magento creates one flat table for each store view.

      – Marius
      Jan 8 '15 at 13:46











    • Yes, Thank you for this answer, couldn't find the right one on the interwebs

      – xvilo
      Jan 8 '15 at 16:01

















    • i only have a table called catalog_product_flat_1, could that be the same?

      – xvilo
      Jan 8 '15 at 12:59











    • yes. I assume you have only one store view in your instance. the 1 at the end is the store view id. Magento creates one flat table for each store view.

      – Marius
      Jan 8 '15 at 13:46











    • Yes, Thank you for this answer, couldn't find the right one on the interwebs

      – xvilo
      Jan 8 '15 at 16:01
















    i only have a table called catalog_product_flat_1, could that be the same?

    – xvilo
    Jan 8 '15 at 12:59





    i only have a table called catalog_product_flat_1, could that be the same?

    – xvilo
    Jan 8 '15 at 12:59













    yes. I assume you have only one store view in your instance. the 1 at the end is the store view id. Magento creates one flat table for each store view.

    – Marius
    Jan 8 '15 at 13:46





    yes. I assume you have only one store view in your instance. the 1 at the end is the store view id. Magento creates one flat table for each store view.

    – Marius
    Jan 8 '15 at 13:46













    Yes, Thank you for this answer, couldn't find the right one on the interwebs

    – xvilo
    Jan 8 '15 at 16:01





    Yes, Thank you for this answer, couldn't find the right one on the interwebs

    – xvilo
    Jan 8 '15 at 16:01













    -1














    I have 4 languages so i truncated 4 tables.
    catalog_product_flat_1, 2, 3, 4





    share|improve this answer





























      -1














      I have 4 languages so i truncated 4 tables.
      catalog_product_flat_1, 2, 3, 4





      share|improve this answer



























        -1












        -1








        -1







        I have 4 languages so i truncated 4 tables.
        catalog_product_flat_1, 2, 3, 4





        share|improve this answer















        I have 4 languages so i truncated 4 tables.
        catalog_product_flat_1, 2, 3, 4






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 31 '18 at 4:23









        Teja Bhagavan Kollepara

        3,01241949




        3,01241949










        answered Dec 31 '18 at 2:35









        hakanhakan

        44




        44



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f51536%2fmagento-indexing-is-failing-sqlstate23000-integrity-constraint-violation%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

            Magento 2 disable Secret Key on URL's from terminal The Next CEO of Stack OverflowMagento 2 Shortcut/GUI tool to perform commandline tasks for windowsIn menu add configuration linkMagento oAuth : Generating access token and access secretMagento 2 security key issue in Third-Party API redirect URIPublic actions in admin controllersHow to Disable Cache in Custom WidgetURL Key not changing in Magento 2Product URL Key gets deleted when importing custom options - Magento 2Problem with reindex terminalMagento 2 - bin/magento Commands not working in Cpanel Terminal

            Aasi (pallopeli) Navigointivalikko