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'),
  );

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)