2014-02-11 64 views
0

我试图定义使用外键 在Drupal 7.我用hook_schema和hook_update功能定义和 更新架构表之间的关系Mysql的语法错误。我收到以下错误。在Drupal 7

$schema['relationship] = array(
    'description' => 'The table for employee organisation relationship', 
    'fields' => array(
     'rid' => array(
      'description' => 'The primary Identifier for a Relationship.', 
      'type' => 'serial', 
      'unsigned' => TRUE, 
      'not null' => TRUE, 
    ), 
     'uid' => array(
      'description' => 'The primary Identifier for User/Employee', 
      'type' => 'int', 
      'unsigned' => TRUE, 
      'not null' => FALSE, 
      'default' => 0, 
    ), 
     'oid' => array(
      'description' => 'The department Identifier of employee employed', 
      'type' => 'int', 
      'unsigned' => TRUE, 
      'not null' => FALSE, 
      'default' => 0, 
), 
    'indexes' => array(
     'uid' => array('uid'), 
    'oid' => array('oid'), 
),  
'foreign keys' => array(
    'uid' => array(
     'table' => 'users', 
      'columns' => array('uid' => 'uid') 
    ), 
     'oid' => array(
     'table' => 'organization', 
     'columns' => array('oid' => 'oid') 
    ), 
), 
    'primary key' => array('rid'), 
) 
); 

失败:PDOException:SQLSTATE [42000]:语法错误或访问 冲突:1064您的SQL语法错误;检查对应于你的MySQL服务器版本正确的语法 利用近“DEFAULT NULL)ENGINE = InnoDB的默认字符集UTF8 COMMENT '的' 第5行的表手动 :CREATE TABLE {组织}(id INT无符号NOT NULL AUTO_INCREMENT COMMENT '的一个关系主要标识符。', uid INT无符号NULL DEFAULT 0 COMMENT,oid INT无符号NULL DEFAULT 0 COMMENT“使用雇员的 部门标识符 '为 用户/雇员主要标识符' 'primary key DEFAULT NULL)ENGINE = InnoDB的缺省字符集UTF8 COMMENT' 为电子表 员工组织关系';阵列()在 db_create_table()(的 Ç2717行:\ XAMPP \ htdocs中\ tutumaudit \包括\数据库\ database.inc)。

回答

0

那么我整理出来自己。我把这些键放在字段数组下。 这是该死的愚蠢,我需要2个小时发现这一点。最后 代码如下:

$schema['relationship] = array(
    'description' => 'The table for employee organisation relationship', 
    'fields' => array(
     'rid' => array(
      'description' => 'The primary Identifier for a Relationship.', 
      'type' => 'serial', 
      'unsigned' => TRUE, 
      'not null' => TRUE, 
    ), 
     'uid' => array(
      'description' => 'The primary Identifier for User/Employee', 
      'type' => 'int', 
      'unsigned' => TRUE, 
      'not null' => FALSE, 
      'default' => 0, 
    ), 
     'oid' => array(
      'description' => 'The department Identifier of employee employed', 
      'type' => 'int', 
      'unsigned' => TRUE, 
      'not null' => FALSE, 
      'default' => 0, 
), 
), 
'indexes' => array(
     'uid' => array('uid'), 
    'oid' => array('oid'), 
),  
'foreign keys' => array(
    'uid' => array(
     'table' => 'users', 
      'columns' => array('uid' => 'uid') 
    ), 
     'oid' => array(
     'table' => 'organization', 
     'columns' => array('oid' => 'oid') 
    ), 
), 
    'primary key' => array('rid'), 
);