I'm working on an .install file for my module in Drupal 7. I want to create two tables, one called tls_connect_floormap_images and one called tls_connect_floormap_coords. I'm not having any trouble with the _images table. But when I try to make the uid field of the _coords table a unique key that auto-increments, I get an error that says:
Fatal error: Unsupported operand types in C:\Program Files (x86)\Zend\Apache2\htdocs\TLSConnect3App\includes\database\mysql\schema.inc on line 85
I get this error on install, When I Save Configuration I get the WSOD with the error message. When I put in the url for /admin/modules there is an error that says Notice: Undefined variable: schema in floormap_install() (line 37 of C:\Program Files (x86)\Zend\Apache2\htdocs\TLSConnect3App\sites\all\modules\custom\TLSConnectPackage\floormap\floormap.install). I see that the module is installed though, and when I check for my tables in phpMyAdmin they are there, uid auto_increments but is not a unique or primary key.
Here is my code:
function floormap_schema(){
$schema['floormap_images'] = array (
'description' => 'Floor map images.',
'fields' => array (
'image' => array('type' => 'blob', 'not null' => TRUE,),
'name' => array( 'type' => 'varchar', 'length' => 30, 'not null' => TRUE,),
'active' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,),
),
'unique keys' => array('name' => array('name'),
),
);
$schema['floormap_coords'] = array (
'description' => 'Floor map images.',
'fields' => array (
'uid' => array( 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE,),
'floormap' => array( 'type' => 'text', 'not null' => TRUE,),
'item_type' => array( 'type' => 'text', 'not null' => TRUE,),
'pos_a_x' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,),
'pos_a_y' => array( 'type' => 'int', 'unsiged' => TRUE, 'not null' => TRUE,),
'pos_b_x' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,),
'pos_b_y' => array( 'type' => 'int', 'unsiged' => TRUE, 'not null' => TRUE,),
'pos_c_x' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,),
'pos_c_y' => array( 'type' => 'int', 'unsiged' => TRUE,' not null' => TRUE,),
'pos_d_x' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,),
'pos_d_y' => array('type' => 'int', 'unsiged' => TRUE, 'not null' => TRUE,),
),
'unique keys' => array('uid' => array('uid'),),
);
return $schema;
}
function floormap_install() {
//Create table to store floor map images if it doesn't already exist
if(!db_table_exists('tls_connect_floormap_images')){
db_create_table('tls_connect_floormap_images',$schema['floormap_images']);
}
//Create table to store floor map coordinates if it doesn't already exist
if(!db_table_exists('tls_connect_floormap_coords')){
db_create_table('tls_connect_floormap_coords',$schema['floormap_coords']);
}
}
I only get the error when I have
'unique keys' => array('uid' => array('uid'),),
in the $schema['floormap_coords'] array. It works in the ['floormap_images'] array though, not sure why its not working for coords. The only difference is that the 'uid' field is serial datatype and name is varchar.