0

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 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Clive, This did remove the error, however it doesn't create the database table at all.
That sounds about right, the module will be in an inconsistent state now (i.e. it thinks that tables have already been installed). Try disabling your module, then go to the 'Uninstall' tab of the modules page and uninstall it completely. Then go back to the modules page and re-enable it. If that still doesn't work, install the devel module and visit mysite.com/devel/reinstall where you can invoke a full re-installation of the module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.