Last updated 19 April 2014. Created on 14 July 2007.
Edited by Plazik, kiamlaluno, ax, bjaspan. Log in to edit this page.

SQL databases require that all columns involved in a table's primary key be declared as NOT NULL. If you declare a primary key column to allow NULL values, MySQL and PostgresQL (probably among others) silently convert the columns to NOT NULL, but you should not rely on this behavior.

For example, this table specification is incorrect:

  $schema['T'] = array(
    'fields' => array(
      'col1' => array(
        'type' => 'int',
      ),
    ),
    'primary key' => array('col1'),
  );

To make this specification correct, add 'not null' => TRUE to the specification for col1.

$schema['T'] = array(
    'fields' => array(
      'col1' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array('col1'),
  );

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

Thomas_Zahreddin’s picture

a default for the colum used as primary key is not allowed for mysql.

(at least the schema modul reports this)