Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
no default if a single colum is used for the primary key
a default for the colum used as primary key is not allowed for mysql.
(at least the schema modul reports this)