drupal db模式错误

时间:2011-09-28 10:45:15

标签: php mysql drupal drupal-7

在我为Drupal 7构建的模块中,我正在尝试为安装和卸载过程创建数据库模式。当启用模块(并因此安装它)时,我收到错误,我的表格没有创建。

有人能看出哪里出错吗?

<?php
/**
 * Implementation of hook_schema().
 */
function wind_and_waves_schema() {
  $schema['wind_and_waves'] = array(
   'description' => 'Caches wind and waves data',
   'fields' => array(
     'id' => array(
       'description' => 'The unique identifier for this item.',
       'type' => 'serial',
       'disp-width' => '11',
       'unsigned' => TRUE,
     ),
     'creation' => array(
       'description' => 'Moment the data has been loaded',
       'mysql_type' => 'datetime',
       'disp-width' => '11',
     ),
     'load_time' => array(
       'description' => 'Moment the wind data has been loaded by rijkswaterstaat',
       'mysql_type' => 'datetime',
       'disp-width' => '11',
     ),
     'hoek_wind_snelheid' => array(
       'description' => 'Windsnelheid op hoek',
       'type' => 'varchar',
       'disp-width' => '11',
     ),
     'hoek_wind_stoot' => array(
       'description' => 'Windstoot op hoek',
       'type' => 'varchar',
       'disp-width' => '11',
     ),
     'hoek_wind_richting' => array(
       'description' => 'Windrichting op hoek',
       'type' => 'varchar',
       'disp-width' => '11',
     ),
     'hoek_golf_hoogte' => array(
       'description' => 'golfhoogte op hoek',
       'type' => 'varchar',
       'disp-width' => '11',
     ),
     'ijmuiden_wind_snelheid' => array(
       'description' => 'Windsnelheid op ijmuiden',
       'type' => 'varchar',
       'disp-width' => '11',
     ),
     'ijmuiden_wind_stoot' => array(
       'description' => 'Windstoot op ijmuiden',
       'type' => 'varchar',
       'disp-width' => '11',
     ),
     'ijmuiden_wind_richting' => array(
       'description' => 'Windrichting op ijmuiden',
       'type' => 'varchar',
       'disp-width' => '11',
     ),
     'ijmuiden_golf_hoogte' => array(
       'description' => 'golfhoogte op ijmuiden',
       'type' => 'varchar',
       'disp-width' => '11',
     ),
     'golf_periode' => array(
       'description' => 'golfperiode',
       'type' => 'varchar',
       'disp-width' => '11',
     ),
     'watertemp' => array(
       'description' => 'watertemperatuur',
       'type' => 'varchar',
       'disp-width' => '11',
     ),
     'luchttemp' => array(
       'description' => 'luchttemperatuur',
       'type' => 'varchar',
       'disp-width' => '11',
     ),
   ),
   'primary key' => array('id'),
  );
  return $schema;
}
?>

我得到的错误:

  

PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在第4行的'DEFAULT NULL COMMENT'Wavesnelheid op hoek',hoek_wind_stoot VARCHAR DEFAULT'附近使用正确的语法:CREATE TABLE {wind_and_waves}(id INT unsigned auto_increment DEFAULT NULL COMMENT'此项的唯一标识符。',creation DATETIME DEFAULT NULL COMMENT'加载数据的时刻',hoek_wind_snelheid VARCHAR DEFAULT NULL评论'Windsnelheid op hoek',{ {1}} VARCHAR DEFAULT NULL COMMENT'Windstoot op hoek',hoek_wind_stoot VARCHAR DEFAULT NULL COMMENT'Wengrichting op hoek',hoek_wind_richting VARCHAR DEFAULT NULL COMMENT'golfhoogte op hoek',hoek_golf_hoogte VARCHAR DEFAULT NULL COMMENT'Windsnelheid op ijmuiden',ijmuiden_wind_snelheid VARCHAR DEFAULT NULL COMMENT'Windstoot op ijmuiden',ijmuiden_wind_stoot VARCHAR DEFAULT NULL COMMENT'Windrichting op ijmuiden',ijmuiden_wind_richting VARCHAR DEFAULT NULL COMMENT'golfhoogte op ijmuiden',ijmuiden_golf_hoogte VARCHAR DEFAULT NULL COMMENT'golfperiode',golf_periode VARCHAR DEFAULT NULL COMMENT'watertemperatuur',watertemp VARCHAR DEFAULT NULL COMMENT'luhtt emperatuur',PRIMARY KEY(luchttemp))ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT'缓存风和波数据'; db_create_table()中的Array()(/home/sitede01/domains/sitedezign.net/public_html/includes/database/database.inc的第2657行)。

1 个答案:

答案 0 :(得分:2)

varchar类型的所有列都需要length属性,例如:

'luchttemp' => array(
   'description' => 'luchttemperatuur',
   'type' => 'varchar',
   'length' => 11
 )

disp-width仅对非varchar 类型列

有效