0

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.

2 Answers 2

0

First of all please provide which version of drupal you are using ?

If you are using d7 than you don't need to check in hook_install is table exists ?

Just provide hook_schema in your module file and it will create your tables. For floormap_coords make uid as primary ( primary key itself unique) 'primary key' => array('uid'),

1
  • I am using Drupal 7 I have already tried making it primary key and get the same error.
    – slpcc63
    Mar 12, 2014 at 12:13
0

When do you get that error message? Is it on installing the module or any time the module is loaded (i.e. a parse error).

The "Unsupported operand types" error indeed seems like something is wrong. However, it usually indicates you are doing division on an array or using a = where it should be a => or something. I tried just compiling/printing the code you pasted here in 3v4l.org and it appears to work fine so I don't see how you could get that error from it.

1
  • I apologize for the incomplete information. 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.
    – slpcc63
    Mar 12, 2014 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.