Question

I am getting following error while trying to reindex catalog_category_flat (Category Flat Data). I did tried to repair the database with PHPMyAdmin and magento database repair tool but still not fix. Can you look into the error and let me know if there is other way to fix the issue?

Stack trace:
#0 /home/cpaneluser/public_html/catalog/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /home/cpaneluser/public_html/catalog/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /home/cpaneluser/public_html/catalog/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /home/cpaneluser/public_html/catalog/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /home/cpaneluser/public_html/catalog/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('truncate catalo...', Array)
#5 /home/cpaneluser/public_html/catalog/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('truncate catalo...', Array)
#6 /home/cpaneluser/public_htm in /home/cpaneluser/public_html/catalog/lib/Zend/Db/Statement/Pdo.php on line 234
[21-Apr-2014 14:16:35 UTC] PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'cpaneluser_magento.catalog_category_flat' doesn't exist' in /home/cpaneluser/public_html/catalog/lib/Zend/Db/Statement/Pdo.php:228

I got another error while trying to repair magento database.

Error #1005: Can't create table 'thestati_magento.catalog_category_flat_store_1' (errno: -1) on SQL: CREATE TABLE `catalog_category_flat_store_1` ( `entity_id` int(10) unsigned NOT NULL COMMENT 'entity_id', `parent_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'parent_id', `created_at` timestamp NULL DEFAULT NULL COMMENT 'created_at', `updated_at` timestamp NULL DEFAULT NULL COMMENT 'updated_at', `path` varchar(255) NOT NULL DEFAULT '' COMMENT 'path', `position` int(11) NOT NULL COMMENT 'position', `level` int(11) NOT NULL DEFAULT '0' COMMENT 'level', `children_count` int(11) NOT NULL COMMENT 'children_count', `store_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Store Id', `all_children` text COMMENT 'All Children', `available_sort_by` text COMMENT 'Available Product Listing Sort By', `children` text COMMENT 'Children', `custom_apply_to_products` int(11) DEFAULT NULL COMMENT 'Apply To Products', `custom_design` varchar(255) DEFAULT NULL COMMENT 'Custom Design', `custom_design_from` datetime DEFAULT NULL COMMENT 'Active From', `custom_design_to` datetime DEFAULT NULL COMMENT 'Active To', `custom_layout_update` text COMMENT 'Custom Layout Update', `custom_use_parent_settings` int(11) DEFAULT NULL COMMENT 'Use Parent Category Settings', `default_sort_by` varchar(255) DEFAULT NULL COMMENT 'Default Product Listing Sort By', `description` text COMMENT 'Description', `display_mode` varchar(255) DEFAULT NULL COMMENT 'Display Mode', `filter_price_range` decimal(12,4) DEFAULT NULL COMMENT 'Layered Navigation Price Step', `image` varchar(255) DEFAULT NULL COMMENT 'Image', `include_in_menu` int(11) DEFAULT NULL COMMENT 'Include in Navigation Menu', `is_active` int(11) DEFAULT NULL COMMENT 'Is Active', `is_anchor` int(11) DEFAULT NULL COMMENT 'Is Anchor', `landing_page` int(11) DEFAULT NULL COMMENT 'CMS Block', `meta_description` text COMMENT 'Meta Description', `meta_keywords` text COMMENT 'Meta Keywords', `meta_title` varchar(255) DEFAULT NULL COMMENT 'Page Title', `name` varchar(255) DEFAULT NULL COMMENT 'Name', `page_layout` varchar(255) DEFAULT NULL COMMENT 'Page Layout', `path_in_store` text COMMENT 'Path In Store', `thumbnail` varchar(255) DEFAULT NULL COMMENT 'Thumbnail Image', `url_key` varchar(255) DEFAULT NULL COMMENT 'URL Key', `url_path` varchar(255) DEFAULT NULL COMMENT 'Url Path', PRIMARY KEY (`entity_id`), KEY `IDX_CATALOG_CATEGORY_FLAT_STORE_1_STORE_ID` (`store_id`), KEY `IDX_CATALOG_CATEGORY_FLAT_STORE_1_PATH` (`path`), KEY `IDX_CATALOG_CATEGORY_FLAT_STORE_1_LEVEL` (`level`), CONSTRAINT `FK_CAT_CTGR_FLAT_STORE_1_ENTT_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FK_CATALOG_CATEGORY_FLAT_STORE_1_STORE_ID_CORE_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Catalog Category Flat (Store 1)'
Was it helpful?

Solution 3

I was bale to fix the issue by exporting the database and importing to new database. Though I had to add new database details to local.xml file.

OTHER TIPS

I tried to fix the missing catalog_category_flat table problem, but could not find a solution other than creating the missing table. After creating for us the problem was solved. This is the SQL to create it:

CREATE TABLE IF NOT EXISTS `catalog_category_flat` (
  `entity_id` int(10) unsigned NOT NULL,
  `store_id` smallint(5) unsigned NOT NULL DEFAULT '0',
  `parent_id` int(10) unsigned NOT NULL DEFAULT '0',
  `path` varchar(255) NOT NULL DEFAULT '',
  `level` int(11) NOT NULL DEFAULT '0',
  `position` int(11) NOT NULL DEFAULT '0',
  `children_count` int(11) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `updated_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `name` varchar(255) NOT NULL DEFAULT '',
  `description` text,
  `image` varchar(255) NOT NULL DEFAULT '',
  `meta_title` varchar(255) NOT NULL DEFAULT '',
  `meta_keywords` text,
  `meta_description` text,
  `landing_page` int(10) NOT NULL DEFAULT '0',
  `display_mode` varchar(255) NOT NULL DEFAULT '',
  `is_active` int(10) NOT NULL DEFAULT '0',
  `is_anchor` int(10) NOT NULL DEFAULT '0',
  `all_children` text,
  `path_in_store` text,
  `children` text,
  `url_key` varchar(255) NOT NULL DEFAULT '',
  `page_layout` varchar(255) NOT NULL DEFAULT '',
  `custom_layout_update` text,
  `url_path` varchar(255) NOT NULL DEFAULT '',
  `custom_design` varchar(255) NOT NULL DEFAULT '',
  `custom_design_apply` int(10) NOT NULL DEFAULT '0',
  `custom_design_from` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `custom_design_to` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `available_sort_by` text,
  `default_sort_by` varchar(255) NOT NULL DEFAULT '',
  KEY `CATEGORY_FLAT_CATEGORY_ID` (`entity_id`),
  KEY `CATEGORY_FLAT_STORE_ID` (`store_id`),
  KEY `path` (`path`),
  KEY `IDX_LEVEL` (`level`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `catalog_category_flat`
  ADD CONSTRAINT `FK_CATEGORY_FLAT_CATEGORY_ID_STORE_0` FOREIGN KEY (`entity_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_CATEGORY_FLAT_STORE_ID_STORE_0` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE;

There are settings under System->Configuration->Catalog->Front End called Use Flat Catalog Category and Use Flat Catalog Product. If these are on, it is likely your problem and you should turn them off and see if that resolves the issue.

Execute this query DELETE FROM `core_resource` WHERE `code` = 'setup-file-name' and reinstall the module

Option1?

  1. Export the Table Design via Export Table Design in MySQL or Adminer (SQL) admin from another storeview, replace all the _storenum and check the indexes for the storenum also. The import as new table design.

  2. Run reindex all on server (Or maybe first via system->index in backend)

  3. You can also save the option in config, flat files = no, click reindex all. Then set flat files = yes and click reindex all again.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top