I have a problem as the title says. My plugin does not create a custom table when it's activated. My code is:

function bsp_create_update_table() 

global $wpdb; //geting the acces to a wp tables
$tablename=$wpdb->prefix . "students"; //the name of a table with it's prefix

//checking if the table with the name we created a line above exists
if($wpdb->get_var("SHOW TABLES LIKE '$tablename'") != $tablename) 

    //if it does not exists we create the table
    $sql="CREATE TABLE `$tablename`(
    `students_id` INT(11) NOT NULL AUTO_INCREMENT,
    `students_name` VARCHAR (50) NOT NULL,
    `students_lastname` VARCHAR (50) NOT NULL,
    `students_email` VARCHAR 850) NOT NULL, 
    `students_course` VARCHAR (100) NOT NULL,
    `students_date` DATETIME,
    PRIMARY KEY (students_id)

    //wordpress function for updating the table
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

And I have a hook like this: register_activation_hook(__FILE__, 'bsp_create_update_table');

When plugin is activated there is no table created and I just don't know why. Any ideas?

  • Is register_activation_hook( ... ) in your main plugin file? Or in an include'ed one? Commented May 13, 2015 at 12:15
  • In my main plugin file.
    – dea
    Commented May 13, 2015 at 18:45

1 Answer 1


To answear my question: It's a typo.

    `students_email` VARCHAR 850) NOT NULL, 

should be:

    `students_email` VARCHAR (50) NOT NULL, 

Oh the headache. When the typo is corrected it creates a new table.

Your Answer

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

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