Hi people,
I have a doubt about the schema api. I've created a schema with a table called pois. This is the
code:
function pois_schema(){
$schema['pois'] = array(
'description' => t('Datos correspondientes al formulario de insercion de Pois'),
'fields' => array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'nombre' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 50,
'default' => '',
),
'descripcion' => array(
'type' => 'text',
'not null' => TRUE,
),
'longitud' => array(
'type' => 'float',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
),
'latitud' => array(
'type' => 'float',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array('nid' => array('nid'),),
'primary key' => array('vid'),
);
return $schema;
}
That's ok. But, how can i create a second table? The following code is what i've tried just after the
definition of the 'pois' table:
$schema['pois_cat'] = array(
'description' => t(''),
'fields' => array(
'id' => array(
'type' => 'serial',
//'unsigned' => 'TRUE',
'not null' => 'TRUE',
'default' => 0,
),
'nombre' => array(
'type' => 'varchar',
'not null' => 'TRUE',
'length' => '25',
'default' => '',
),
),
'indexes' => array('id' => array('id'),),
'primary key' => array('id'),
);
Is this the rigth way??? Index and primary key can be the same field????
Thanks to everyone for any help.
Comments
Hey, Remember that each
Hey,
Remember that each $schema is an array. The name of the slot will be the table name and the definition will be the tables definithion. So just keep adding to the array and return that array. That will then build your table.
Davin
I've just solved it
Hi Trappies,
Thanks for the help. I 've solved it a few minutes ago. After i've understood that 'schema' works
as an array with the tables i see all clearer.
Thanks again.
no problem ;)
no problem ;)