【问题标题】:Mysql Syntax Error in Drupal 7Drupal 7 中的 Mysql 语法错误
【发布时间】:2014-02-11 06:42:36
【问题描述】:

我正在尝试使用外键定义表之间的关系 在 drupal 7. 我使用 hook_schema 和 hook_update 函数来定义和 更新架构。我收到以下错误。

$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 DEFAULT CHARACTER SET utf8 COMMENT 'The table for' 在第 5 行:CREATE TABLE {组织}(idINT 无符号非空 auto_increment COMMENT '关系的主要标识符。', uid INT unsigned NULL DEFAULT 0 COMMENT '主标识符 用户/员工',oid INT 无符号 NULL DEFAULT 0 COMMENT ' 雇员的部门标识符',primary keyDEFAULT NULL ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT '表 为员工组织关系”;数组 ( ) 在 db_create_table()(第 2717 行 C:\xampp\htdocs\tutumaudit\includes\database\database.inc)。

【问题讨论】:

    标签: drupal mysql-error-1064


    【解决方案1】:

    嗯,我自己解决了。我将这些键放在字段数组下。 那真是太愚蠢了,我需要 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'),
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多