1

I want to build a installable module. Let's assume the module name will be bluedog_calculator. I have already created other required files like bluedog_calculator.info and bluedog_calculator.module. Now I am trying to use hook_schema() and whenever i am trying to use drush dre bluedog_calculator -y, Konsole gives me an error as follows:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; [error] check the manual that corresponds to your MariaDB server version for the right syntax to use near 'unsigned NOT NULL COMMENT.

I am not sure what is the right syntax for applying this hook.

My code is

function bluedog_calculator_schema(){
    $schema['bluedog_calculator_machine'] = array(
    'description' => 'TODO: please describe this table!',
    'fields' => array(
      'id' => array(
        'description' => 'TODO: please describe this field!',
        'type' => 'serial',
        'not null' => TRUE,
        ),
      'name' => array(
        'description' => 'TODO: please describe this field!',
        'type' => 'varchar',
        'length' => '100',
        'not null' => TRUE,
        ),
      'speed' => array(
        'description' => 'TODO: please describe this field!',
        'type' => 'float',
        'not null' => TRUE,
        ),
      'cost' => array(
        'description' => 'TODO: please describe this field!',
        'type' => 'float',
        'not null' => TRUE,
        ),
      'image' => array(
        'description' => 'TODO: please describe this field!',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        ),
      'web_link' => array(
        'description' => 'TODO: please describe this field!',
        'type' => 'text',
        'unsigned' => TRUE,
        'not null' => TRUE,
        ),
      'is_default' => array(
        'description' => 'TODO: please describe this field!',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
        ),
      ),
    'primary key' => array('id'),
);

return $schema;
}

2 Answers 2

2

The only place you use 'unsigned' is in this block:

'web_link' => array(
  'description' => 'TODO: please describe this field!',
  'type' => 'text',
  'unsigned' => TRUE,
  'not null' => TRUE,
),

'unsigned' does not apply to text columns. Try removing that line from the web_link column definition. https://api.drupal.org/api/drupal/includes!database!schema.inc/group/schemaapi/7.x has useful reference on this.

(The docs state that unsigned is ignored for other types, but it seems the error is in that chunk, so I'd certainly try removing it in case your database engine is not ignoring it.)

1

I didn't try. But I believe that not null and default should not appear at the same time in a field.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.