1

我正在尝试运行一个脚本来在 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。有什么线索吗?谢谢!!!

4

1 回答 1

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;
于 2013-02-06T10:50:12.800 回答