0

I'm trying to set up an install file for a custom module that I'm creating but having a little trouble when Drupal tries to create my tables.

It's probably a simple syntax error but can't track it down at all. Here's the error I'm getting:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT NULL, `logo_url` VARCHAR DEFAULT NULL, `url` VARCHAR DEFAULT NULL COMM' at line 3: CREATE TABLE {survey_compare_companies} ( `id` INT unsigned NOT NULL auto_increment COMMENT 'The primary key for this table.', `company_name` VARCHAR DEFAULT NULL, `logo_url` VARCHAR DEFAULT NULL, `url` VARCHAR DEFAULT NULL COMMENT 'The company’s website address.', `int_url` VARCHAR DEFAULT NULL COMMENT 'URL to the Survey Compare page for this company', `payment_per_survey` VARCHAR DEFAULT NULL COMMENT 'The payment amount per survey', `min_payout` VARCHAR DEFAULT NULL COMMENT 'The minimum amount required to qualify for a payout', `ave_survey_length` VARCHAR DEFAULT NULL COMMENT 'The average length of individual surveys', `ref_bonus` VARCHAR DEFAULT NULL COMMENT 'The bonus offered for referrals', `other_bonus` VARCHAR DEFAULT NULL COMMENT 'Details of other bonuses', `age_id` INT DEFAULT NULL COMMENT 'The ID of the age group that this company offers surveys to', PRIMARY KEY (`id`) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'Holds details for various survey companies'; Array ( ) in db_create_table() (line 2717 of C:\xampp\htdocs\drupal\includes\database\database.inc).

Here's my code:

<?php

/**
* Implements hook_schema()
*/

function survey_compare_schema() {

    $schema = array();

    $schema['survey_compare_companies'] = array(

        'description' => 'Holds details for various survey companies',

        'fields' => array(

            'id' => array(
                'description'   => 'The primary key for this table.',
                'type'          => 'serial',
                'unsigned'      => TRUE,
                'not null'      => TRUE
            ),

            'company_name' => array(
                'description'   => 'The name of the company.',
                'type'          => 'varchar'
            ),

            'logo_url' => array(
                'description'   => "A URL to the company's logo",
                'type'          => 'varchar'
            ),

            'url' => array(
                'description'   => "The company's website address.",
                'type'          => 'varchar'
            ),

            'int_url' => array(
                'description'   => 'URL to the Survey Compare page for this company',
                'type'          => 'varchar'
            ),

            'payment_per_survey' => array(
                'description'   => 'The payment amount per survey',
                'type'          => 'varchar'
            ),

            'min_payout' => array(
                'description'   => 'The minimum amount required to qualify for a payout',
                'type'          => 'varchar'
            ),

            'ave_survey_length' => array(
                'description'   => 'The average length of individual surveys',
                'type'          => 'varchar'
            ),

            'ref_bonus' => array(
                'description'   => 'The bonus offered for referrals',
                'type'          => 'varchar'
            ),

            'other_bonus' => array(
                'description'   => 'Details of other bonuses',
                'type'          => 'varchar'
            ),

            'age_id' => array(
                'description'   => 'The ID of the age group that this company offers surveys to',
                'type'          => 'int'
            )

        ),

        'primary key' => array('id')

    );

$schema['survey_compare_payment_types'] = array(

    'description' => 'Holds details about the types of payment offered',

    'fields' => array(

        'id' => array(
            'description'   => 'The primary key for this table.',
            'type'          => 'serial',
            'unsigned'      => TRUE,
            'not null'      => TRUE
        ),

        'name' => array(
            'description'   => 'The name of this payment type',
            'type'          => 'varchar'
        )

    )

);

$schema['survey_compare_companies_payment_types_relation'] = array(

    'description' => 'Specifies links between companies and the payment types that they offer',

    'fields' => array(

        'id' => array(
            'description'   => 'The primary key for this table.',
            'type'          => 'serial',
            'unsigned'      => TRUE,
            'not null'      => TRUE
        ),

        'company_id' => array(
            'description'   => 'The ID of the company',
            'type'          => 'int'
        ),

        'payment_type_id' => array(
            'description'   => 'The ID of the payment type',
            'type'          => 'int'
        )

    )

);

$schema['survey_compare_min_age'] = array(

    'description' => 'Specifies the minimum age required to fill in surveys for this company',

    'fields' => array(

        'id' => array(
            'description'   => 'The primary key for this table.',
            'type'          => 'serial',
            'unsigned'      => TRUE,
            'not null'      => TRUE
        ),

        'min_age' => array(
            'description'   => 'The minimum age',
            'type'          => 'int'
        )

    )

);

$schema['survey_compare_payment_options'] = array(

    'description' => 'Specifies the payment options available',

    'fields' => array(

        'id' => array(
            'description'   => 'The primary key for this table.',
            'type'          => 'serial',
            'unsigned'      => TRUE,
            'not null'      => TRUE
        ),

        'name' => array(
            'description'   => 'The name of this payment option',
            'type'          => 'varchar'
        ),

        'logo_url' => array(
            'description'   => 'The URL to the logo for this payment option',
            'type'          => 'varchar'
        )

    )

);

$schema['survey_compare_companies_payment_options_relation'] = array(

    'description' => 'Specifies links between companies and the payment options that they offer',

    'fields' => array(

        'id' => array(
            'description'   => 'The primary key for this table.',
            'type'          => 'serial',
            'unsigned'      => TRUE,
            'not null'      => TRUE
        ),

        'company_id' => array(
            'description'   => 'The ID of the company',
            'type'          => 'int'
        ),

        'option_id' => array(
            'description'   => 'The ID of the payment option',
            'type'          => 'int'
        )

    )

);

$schema['survey_compare_countries'] = array(

    'description' => 'Specifies countries for use with this module',

    'fields' => array(

        'id' => array(
            'description'   => 'The primary key for this table.',
            'type'          => 'serial',
            'unsigned'      => TRUE,
            'not null'      => TRUE
        ),

        'name' => array(
            'description'   => 'The name of the country',
            'type'          => 'varchar'
        ),

        'country_code' => array(
            'description'   => 'The country code',
            'type'          => 'varchar'
        )

    )

);

$schema['survey_compare_companies_countries_relation'] = array(

    'description' => 'Specifies links between companies and the countries that they cover',

    'fields' => array(

        'id' => array(
            'description'   => 'The primary key for this table.',
            'type'          => 'serial',
            'unsigned'      => TRUE,
            'not null'      => TRUE
        ),

        'company_id' => array(
            'description'   => 'The ID of the company',
            'type'          => 'int'
        ),

        'country_id' => array(
            'description'   => 'The ID of the country',
            'type'          => 'int'
        )

    )

);

return $schema;

}

I've tried reading the error but without seeing the whole statement, I'm ha

  • save yourself the headache (because I cant see if offhand either ...). Make this table + fields in MySQL using PHPMYADMIN or whatever Admin UI tool you want. Then install in the Schema and copy and paste the $schema definition it gives you for this table in the drupal admin area. It will take you 5 mins. – tenken Dec 3 '13 at 16:02
1

length is required for varchar columns...

All tables except the first are missing a primary key, as well. Also, adding some indexes will probably save you some performance problems down the line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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