2013-02-06 59 views
1

我想运行脚本来创建Magento中的自定义表 但它会给出错误。 这是我的脚本 -Magento创建表错误

<?php 

    $installer = $this; 
$installer->startSetup(); 
$installer->run(" 

-- DROP TABLE IF EXISTS {$this->getTable('module')}; 
CREATE TABLE {$this->getTable('module')} (
    'module_id' int(11) unsigned NOT NULL auto_increment, 
    'cust_id' varchar(20) NOT NULL, 
    PRIMARY KEY (`module_id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
"); 
$installer->endSetup(); 

我的错误日志看起来像这样。

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error  
in your SQL syntax; check the manual that corresponds to your MySQL server version for  
the right syntax to use near ''module_id' int(11) unsigned NOT NULL auto_increment, 
'cust_id' varchar(20) NO' at line 3 in 
C:\wamp\www\magento\lib\Zend\Db\Statement\Pdo.php on line 228 

Call Stack 
/#TimeMemoryFunctionLocation 
10.0019379872{main}()..\index.php:0 
20.0114765224Mage::run()..\index.php:87 
30.03492000528Mage_Core_Model_App->run()..\Mage.php:683 
40.06713061480Mage_Core_Model_App->_initModules()..\App.php:343 
51.13563312608Mage_Core_Model_Resource_Setup::applyAllUpdates()..\App.php:417 
61.22758029488Mage_Core_Model_Resource_Setup->applyUpdates()..\Setup.php:235 
71.22798027824Mage_Core_Model_Resource_Setup->_installResourceDb()..\Setup.php:327 
81.22798027920Mage_Core_Model_Resource_Setup->_modifyResourceDb()..\Setup.php:421 
91.23228033648include('C:\wamp\www\magento\app\code\community\module\sql\module_setup\mysql4-install-0.1.0.php')..\Setup.php:624 
101.23558112592Mage_Core_Model_Resource_Setup->run()..\mysql4-install-0.1.0.php:13 
111.23558112592Varien_Db_Adapter_Pdo_Mysql->multiQuery()..\Setup.php:933 
121.23558112592Varien_Db_Adapter_Pdo_Mysql->multi_query()..\Mysql.php:590) 

我正在运行magento 1.7和mysql版本5.5.24。 任何线索? 谢谢!

回答

0

花式报价在module_id附近缺失。使用此查询,

DROP TABLE IF EXISTS {$this->getTable('module')}; 
CREATE TABLE {$this->getTable('module')} (
    `module_id` int(11) unsigned NOT NULL auto_increment, 
    `cust_id` varchar(20) NOT NULL, 
    PRIMARY KEY (`module_id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
+0

是的,我只是想通了出来。尽管非常感谢你,但我会尽快接受你的回答:) – BlahBlah