2012-03-14 196 views
0

我想在使用hook_schema函数的Drupal数据库中创建一个表,但我得到了我无法解决的PDO异常错误。这将是巨大的,如果你能提供给我一个解决我的问题Drupal表创建错误

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 'DEFAULT '' COMMENT 
'first name of the user', `lname` VARCHAR DEFAULT '' COMMENT' at line 3: 
CREATE TABLE {mage_user} (`uid` INT unsigned NOT NULL auto_increment COMMENT 
'The foreign identifier for a mage user.', `fname` VARCHAR DEFAULT '' 
COMMENT 'first name of the user', `lname` VARCHAR DEFAULT '' COMMENT 
'last name of the user', `address1` VARCHAR(255) DEFAULT '' COMMENT 
'adress line 1', `address2` VARCHAR(255) DEFAULT '' COMMENT 'adress line 2', 
`postcode` VARCHAR(7) DEFAULT '' COMMENT 'postcode', `gender` VARCHAR(6) 
DEFAULT '' COMMENT 'gender') ENGINE = InnoDB DEFAULT CHARACTER SET utf8 
COMMENT 'The base table for mage user.'; Array () in db_create_table() 
(line 2688 of E:\Server\drupal\includes\database\database.inc). 

我使用

的Apache/2.2.22(的Win32)PHP/5.3.10 MySQL客户端版本:5.0.8 mysqlnd -dev - 20102224 - $修订:321634 $

MySQL服务器版本21年5月5日

和我的模式定义为

function mageacc_schema() { 

      $schema['mageuser'] = array(
     'description' => 'The base table for mage user.', 
     'fields' => array(
     'uid' => array(
     'description' => 'The foreign identifier for a mage user.', 
     'type' => 'serial', 
     'not null' => TRUE, 
), 
    'fname' => array(
    'description' => 'first name of the user', 
    'type' => 'varchar', 
    'lenght' => 255, 
    'default' => '', 
), 
     'lname' => array(
     'description' => 'last name of the user', 
     'type' => 'varchar', 
     'lenght' => 255, 
     'default' => '', 
), 
    'address1' => array(
    'description' => 'adress line 1', 
    'type' => 'varchar', 
    'length' => 255, 
    'default' => '', 

), 
    'address2' => array(
     'description' => 'adress line 2', 
     'type' => 'varchar', 
     'length' => 255, 
     'default' => '', 

    ), 
    'postcode' => array(
     'description' => 'postcode', 
     'type' => 'varchar', 
     'length' => 7, 
     'default' => '', 
    ), 
    'gender'=>array(
    'description' => 'gender', 
    'type' => 'varchar', 
    'length' => 6, 
    'default' => '', 
    ), 

), 

     ); 

    return $schema; 

} 

预先感谢

+1

如果你包含你正在使用的模式定义将是有帮助的 – 2012-03-14 12:29:32

+0

嗨Josep ..我已经添加了模式定义,如果你能告诉我我哪里出错了,这将是有帮助的。 – H4v0cCr8oR 2012-03-14 14:53:10

回答

2

我发现了一些有'length'属性的拼写错误。尝试在fnamelname中首先修复它们以查看它是否有效。

+0

谢谢你的解决方案。 – H4v0cCr8oR 2012-03-14 15:43:42

+0

不客气。这是Drupal编码恐怕很常见的错误。 – 2012-03-14 15:46:47