0
votes

In a module I'm building for Drupal 7 I'm trying to create a DB schema for the installing and uninstalling process. When enabling the module (and thus installing it) I get an error and my table is not created.

Can anybody see where it's going wrong?

<?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;
}
?>

The error I get:

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 NULL COMMENT 'Windsnelheid op hoek', hoek_wind_stoot VARCHAR DEFAULT ' at line 4: CREATE TABLE {wind_and_waves} ( id INT unsigned auto_increment DEFAULT NULL COMMENT 'The unique identifier for this item.', creation DATETIME DEFAULT NULL COMMENT 'Moment the data has been loaded', hoek_wind_snelheid VARCHAR DEFAULT NULL COMMENT 'Windsnelheid op hoek', hoek_wind_stoot VARCHAR DEFAULT NULL COMMENT 'Windstoot op hoek', hoek_wind_richting VARCHAR DEFAULT NULL COMMENT 'Windrichting op hoek', hoek_golf_hoogte VARCHAR DEFAULT NULL COMMENT 'golfhoogte op hoek', ijmuiden_wind_snelheid VARCHAR DEFAULT NULL COMMENT 'Windsnelheid op ijmuiden', ijmuiden_wind_stoot VARCHAR DEFAULT NULL COMMENT 'Windstoot op ijmuiden', ijmuiden_wind_richting VARCHAR DEFAULT NULL COMMENT 'Windrichting op ijmuiden', ijmuiden_golf_hoogte VARCHAR DEFAULT NULL COMMENT 'golfhoogte op ijmuiden', golf_periode VARCHAR DEFAULT NULL COMMENT 'golfperiode', watertemp VARCHAR DEFAULT NULL COMMENT 'watertemperatuur', luchttemp VARCHAR DEFAULT NULL COMMENT 'luchttemperatuur', PRIMARY KEY (id) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'Caches wind and waves data'; Array ( ) in db_create_table() (line 2657 of /home/sitede01/domains/sitedezign.net/public_html/includes/database/database.inc).

1

1 Answers

2
votes

All columns of type varchar need a length property, e.g.:

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

disp-width is only valid for non-varchar type columns