mysql - 未找到基表或 View : 1146 Tablecatalog_product_entity doesn't exist

标签 mysql magento-1.9

我遇到了这个错误

      SQLSTATE[42S02]: Base table or view not found: 1146 Table 'xxxx_mage.catalog_product_entity' doesn't exist, query was: SELECT * FROM catalog_product_entity ORDER BY CAST(sku AS unsigned) DESC LIMIT 1

#0 /home/angeecom/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(65): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/angeecom/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /home/angeecom/public_html/lib/Zend/Db/Adapter/Abstract.php(270): Zend_Db_Statement->execute(Array)
#3 /home/angeecom/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(133): Zend_Db_Adapter_Abstract->query('SELECT * FROM c...', Array)
#4 /home/angeecom/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(331): Zend_Db_Adapter_Pdo_Abstract->query('SELECT * FROM c...', Array)
#5 /home/angeecom/public_html/app/design/adminhtml/default/default/template/catalog/product/edit.phtml(136): Varien_Db_Adapter_Pdo_Mysql->query('SELECT * FROM c...')
#6 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Template.php(241): include('/home/angeecom/...')
#7 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml/defau...')
#8 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#9 /home/angeecom/public_html/app/code/core/Mage/Adminhtml/Block/Template.php(81): Mage_Core_Block_Template->_toHtml()
#10 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Adminhtml_Block_Template->_toHtml()
#11 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract->toHtml()
#12 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Text_List->_toHtml()
#13 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Abstract.php(637): Mage_Core_Block_Abstract->toHtml()
#14 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Abstract.php(581): Mage_Core_Block_Abstract->_getChildHtml('content', true)
#15 /home/angeecom/public_html/app/design/adminhtml/default/default/template/page.phtml(67): Mage_Core_Block_Abstract->getChildHtml('content')
#16 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Template.php(241): include('/home/angeecom/...')
#17 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml/defau...')
#18 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#19 /home/angeecom/public_html/app/code/core/Mage/Adminhtml/Block/Template.php(81): Mage_Core_Block_Template->_toHtml()
#20 /home/angeecom/public_html/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Adminhtml_Block_Template->_toHtml()
#21 /home/angeecom/public_html/app/code/core/Mage/Core/Model/Layout.php(555): Mage_Core_Block_Abstract->toHtml()
#22 /home/angeecom/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(390): Mage_Core_Model_Layout->getOutput()
#23 /home/angeecom/public_html/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php(269): Mage_Core_Controller_Varien_Action->renderLayout()
#24 /home/angeecom/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_Catalog_ProductController->editAction()
#25 /home/angeecom/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('edit')
#26 /home/angeecom/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#27 /home/angeecom/public_html/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#28 /home/angeecom/public_html/app/Mage.php(423): Mage_Core_Model_App->run(Array)
#29 /home/angeecom/public_html/index.php(54): Mage::run('', 'store')
#30 {main}

table 就在那里。这是 mysql 的脚本:

<?php
$installer = $this;
$installer->startSetup();
$installer->run(
	"DROP TABLE IF EXISTS {$this->getTable('netsol_social_discount')};
	
	CREATE TABLE IF NOT EXISTS {$this->getTable('netsol_social_discount')} (
		`id` int(11) NOT NULL,
		`product_id` int(11) NOT NULL,
		`media` varchar(30) NOT NULL,
		`ip_address` varchar(50) NOT NULL,
		`coupon_code` varchar(30) NOT NULL,
		`coupon_used` enum('1','0') NOT NULL DEFAULT '0',
		`creation_date` datetime NOT NULL,
		`coupon_used_date` datetime NOT NULL,
		`magento_order_id` varchar(50) NOT NULL
	) ENGINE=InnoDB DEFAULT CHARSET=latin1;
	
	ALTER TABLE {$this->getTable('netsol_social_discount')} ADD PRIMARY KEY (`id`);
	
	ALTER TABLE {$this->getTable('netsol_social_discount')} MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
	
	UPDATE `catalog_eav_attribute` SET `is_used_for_promo_rules` = 1 WHERE `attribute_id` = (SELECT `attribute_id` FROM `eav_attribute` WHERE `attribute_code` = 'sku' AND entity_type_id = (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_type_code` = 'catalog_product') LIMIT 1);"
);
$installer->endSetup();

$catalogSetup = new Mage_Eav_Model_Entity_Setup('core_setup');
$catalogSetup->startSetup();
$catalogSetup->addAttribute('catalog_product', 'enable_social_discount', array(
	'type' => 'int',
	'backend' => '',
	'frontend' => '',
	'label' => 'Enable Social Discount',
	'input' => 'boolean',
	'class' => '',
	'source' => 'adminhtml/system_config_source_yesno',
	'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
	'visible' => true,
	'required' => false,
	'user_defined' => true,
	'default' => 1,
	'searchable' => true,
	'filterable' => false,
	'comparable' => false,
	'visible_on_front' => false,
	'unique' => false,
	'group' => 'General',
	'attribute_set' => 'Default'
));
$catalogSetup->endSetup();

其余部分在另一个文件中:

<?php
/*
 * @desc: Default enable social discount for all products on installation
*/

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('enable_social_discount');
if($products->count()) {
	Mage::getSingleton('core/resource_iterator')->walk($products->getSelect(), array('socialDiscountCallback'));
}

function socialDiscountCallback($args) {
	$product = Mage::getModel('catalog/product');
	$product->setData($args['row']); //map data to product model
    $product->setEnableSocialDiscount(1);
    $product->getResource()->saveAttribute($product, 'enable_social_discount');
}

可能是什么问题?我尝试创建有帮助的表和属性,但现在当我添加产品时出现此错误。

谢谢

最佳答案

就我而言,是数据库前缀造成了问题。我删除了所有前缀,一切正常。

关于mysql - 未找到基表或 View : 1146 Tablecatalog_product_entity doesn't exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32170488/

相关文章:

php - Magento 1.9 - 模块中的多个助手

sql - 使用 phpmyadmin 管理重复项

mysql - Magento DB 充满了\\r\\n\\。如何删除它们?

php - 将数据库复制到新数据库中,包括结构和数据

mysql - 优先考虑 MySQL 中的左连接行

mysql - 为什么引入日期参数​​会弄乱我的查询? mySQL 中的 3 个表 JOIN

php - 第 29313 行的 fatal error : Class 'Magento_Db_Adapter_Pdo_Mysql' not found in/home/xxxx/public_html/xx/xx/includes/src/__default. php

php - Magento - 从购物车中删除产品

mysql - ORDER BY [My]SQLite 上文本列的离散值]

MySQL:从引用两个其他表的一个表中选择字段