Last updated October 21, 2012. Created by bjaspan on July 14, 2007.
Edited by kiamlaluno, ax. 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:

<?php
$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.

<?php
$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

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

(at least the schema modul reports this)

Thomas

Combining IT and arts to organize
http://it-arts.org