I am creating a simple module. In that module I need to save the values in a table and I have created an .install file to create the table when the module is installed.
While installing the module, it is not creating the table and it gives a PDOException Error. I am unable to find the issue with my code.
The error message:
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 'unsigned NOT NULL COMMENT ' AMOUNT',
rate
unsigned NOT NULL COMMENT 'R' at line 3: CREATE TABLE {sampletest} (id
INT unsigned NOT NULL COMMENT 'My unique identifier',amount
unsigned NOT NULL COMMENT 'AMOUNT',rate
unsigned NOT NULL COMMENT ' RATE',time
unsigned NOT NULL COMMENT ' TIME', PRIMARY KEY (id
) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT ' table'; Array ( ) in db_create_table() (line 2717 of H:\xampp\htdocs\drupal7\includes\database\database.inc) ;
Content of the .install file :
<?php
/**
* Implements hook_install().
*/
function sampletest_install() {
drupal_install_schema('sampletest');
}
/**
* Implements hook_install().
*/
function sampletest_uninstall() {
drupal_uninstall_schema('sampletest');
}
/**
* Implements hook_schema().
*/
function sampletest_schema() {
$schema['sampletest'] = array(
'description' => t('EMI table'),
'fields' => array(
'id' => array(
'description' => t('My unique identifier'),
'type' => 'int',
'unsigned' => true,
'not null' => true,
),
'amount' => array(
'description' => t('AMOUNT'),
'type' => 'bigint',
'unsigned' => true,
'not null' => true,
),
'rate' => array(
'description' => t('RATE'),
'type' => 'bigint',
'unsigned' => true,
'not null' => true,
),
'time' => array(
'description' => t('TIME'),
'type' => 'bigint',
'unsigned' => true,
'not null' => true,
),
),
'primary key' => array('id'),
);
return $schema;
}