I am trying to create 2 tables, linked together, using this code:
$schema['parent'] = array(
"fields" => array(
"id" => array(
'description' => 'The primary identifier',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'data' => array(
'description' => 'The stored data.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('id'),
);
$schema['child'] = array(
// {{{fields
"fields" => array(
"id" => array(
'description' => 'The primary identifier',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
"parent_id" => array(
'type' => 'int',
'unsigned' => TRUE,
),
'data' => array(
'description' => 'The stored data.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
// }}}
'indexes' => array(
"parent_id" => array("parent_id"),
),
'foreign keys' => array(
'parent_id' => array(
'table' => 'parent',
'columns' => array('id' => 'parent_id'),
),
),
'primary key' => array('id'),
);
foreach ($schema as $key => $value) {
print $key . "\n";
db_create_table($key, $value);
}
The tables are created, but the foreign keys are not. Using MySQL/InnoDB. How to fix it?
Also how to set ON DELETE CASCADE and ON UPDATE CASCADE?