WordPress plugin tables are not created after update to 4.2

I am creating a wordpress plugin. This plugin creates some custom tables. Using wordpress 4.1 everything was working fine. After the update to 4.2 the plugin creates only teachers and holidays tables. Here is my code:

register_activation_hook( __FILE__, 'utt_install' );

function utt_install(){

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    global $wpdb;
    $periodsTable=$wpdb->prefix."utt_periods";
    $subjectsTable=$wpdb->prefix."utt_subjects";
    $groupsTable=$wpdb->prefix."utt_groups";
    $teachersTable=$wpdb->prefix."utt_teachers";
    $classroomsTable=$wpdb->prefix."utt_classrooms";
    $lessonsTable=$wpdb->prefix."utt_lessons";
    $holidaysTable=$wpdb->prefix."utt_holidays";
    $eventsTable=$wpdb->prefix."utt_events";
    $lessonsView=$wpdb->prefix."utt_lessons_view";

    $sql = "CREATE TABLE IF NOT EXISTS `$periodsTable` (
            `periodID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
            `year` YEAR NOT NULL COMMENT 'το έτος - έτσι θα μπορεί να κρατηθεί και ιστορικό σε βάθος χρόνου',
            `semester` ENUM('Ε','Χ') NOT NULL COMMENT 'Εαρινό, Χειμερινό',
            PRIMARY KEY (`periodID`))
            ENGINE = InnoDB
            DEFAULT CHARACTER SET = utf8
            COLLATE = utf8_general_ci;";
    dbDelta($sql);

    $sql="CREATE TABLE IF NOT EXISTS `$subjectsTable` (
            `subjectID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
            `title` VARCHAR(64) NOT NULL COMMENT 'το επίσημο όνομα του μαθήματος',
            `type` ENUM('Θ','Ε','ΑΠ') NOT NULL COMMENT 'Θεωρία, Εργαστήριο, Άσκηση-Πράξη',
            `semester` TINYINT UNSIGNED NOT NULL COMMENT 'το εξάμηνο σπουδών στο οποίο απευθύνεται το μάθημα',
            `is_enabled` TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'εαν το μάθημα είναι ενεργό - η εφαρμογή θα προβάλει μόνο τα ενεργά μαθήματα',
            `color` VARCHAR(45) NOT NULL COMMENT 'Το χρώμα που θα εμφανίζεται στο πρόγραμμα.',
            PRIMARY KEY (`subjectID`))
            ENGINE = InnoDB
            DEFAULT CHARACTER SET = utf8
            COLLATE = utf8_general_ci;";
    dbDelta($sql);

    $sql="CREATE TABLE IF NOT EXISTS `$groupsTable` (
            `groupID` INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'μοναδικό μέσω ευρετηρίου UQ - για χρήση ως FKey στον Lessons',
            `periodID` INT UNSIGNED NOT NULL COMMENT 'FKey από Periods',
            `subjectID` INT UNSIGNED NOT NULL COMMENT 'FKey από Subjects',
            `groupName` VARCHAR(20) NOT NULL COMMENT 'το όνομα της ομάδας (εργαστηριακής, κτλ)',
            PRIMARY KEY (`periodID`, `subjectID`, `groupName`),
            INDEX `fk_Groups_Periods_idx` (`periodID` ASC),
            INDEX `fk_Groups_Subject1_idx` (`subjectID` ASC),
            UNIQUE INDEX `groupID_UNIQUE` (`groupID` ASC),
            CONSTRAINT `fk_Groups_Periods`
            FOREIGN KEY (`periodID`)
            REFERENCES `$periodsTable` (`periodID`)
            ON DELETE RESTRICT
            ON UPDATE CASCADE,
            CONSTRAINT `fk_Groups_Subjects`
            FOREIGN KEY (`subjectID`)
            REFERENCES `$subjectsTable` (`subjectID`)
            ON DELETE RESTRICT
            ON UPDATE CASCADE)
            ENGINE = InnoDB
            DEFAULT CHARACTER SET = utf8
            COLLATE = utf8_general_ci;";
    dbDelta($sql);

    $sql="CREATE TABLE IF NOT EXISTS `$teachersTable` (
            `teacherID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
            `surname` VARCHAR(35) NOT NULL,
            `name` VARCHAR(35) NULL,
            PRIMARY KEY (`teacherID`))
            ENGINE = InnoDB
            DEFAULT CHARACTER SET = utf8
            COLLATE = utf8_general_ci;";
    dbDelta($sql);

    $sql="CREATE TABLE IF NOT EXISTS `$classroomsTable` (
            `classroomID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
            `name` VARCHAR(35) NOT NULL,
            `type` ENUM('Δ','Ε') NOT NULL COMMENT 'Διαλέξεων, Εργαστηρίου',
            `is_available` TINYINT(1) NOT NULL DEFAULT 1,
            PRIMARY KEY (`classroomID`))
            ENGINE = InnoDB
            DEFAULT CHARACTER SET = utf8
            COLLATE = utf8_general_ci;";
    dbDelta($sql);

    $sql="CREATE TABLE IF NOT EXISTS `$lessonsTable` (
            `lessonID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
            `groupID` INT UNSIGNED NOT NULL COMMENT 'FKey από Groups',
            `classroomID` SMALLINT UNSIGNED NOT NULL COMMENT 'FKey από Classrooms',
            `teacherID` SMALLINT UNSIGNED NOT NULL COMMENT 'FKey από Teachers',
            `start` DATETIME NOT NULL COMMENT 'το date part καθορίζει την ημερομηνία και το time part την ώρα έναρξης',
            `end` DATETIME NOT NULL,
            INDEX `fk_Lesson_Classrooms1_idx` (`classroomID` ASC),
            INDEX `fk_Lesson_Teachers1_idx` (`teacherID` ASC),
            PRIMARY KEY (`lessonID`),
            CONSTRAINT `fk_Lessons_Classrooms`
            FOREIGN KEY (`classroomID`)
            REFERENCES `$classroomsTable` (`classroomID`)
            ON DELETE RESTRICT
            ON UPDATE CASCADE,
            CONSTRAINT `fk_Lessons_Teachers`
            FOREIGN KEY (`teacherID`)
            REFERENCES `$teachersTable` (`teacherID`)
            ON DELETE RESTRICT
            ON UPDATE CASCADE,
            CONSTRAINT `fk_Lessons_Groups1`
            FOREIGN KEY (`groupID`)
            REFERENCES `$groupsTable` (`groupID`)
            ON DELETE RESTRICT
            ON UPDATE CASCADE)
            ENGINE = InnoDB
            DEFAULT CHARACTER SET = utf8
            COLLATE = utf8_general_ci;";

    dbDelta($sql);

    $sql="CREATE TABLE IF NOT EXISTS `$holidaysTable` (
            `holidayDate` DATE NOT NULL,
            `holidayName` VARCHAR(45) NOT NULL,
            PRIMARY KEY (`holidayDate`))
            ENGINE = InnoDB
            DEFAULT CHARACTER SET = utf8
            COLLATE = utf8_general_ci;";
    dbDelta($sql);

    $sql="CREATE TABLE IF NOT EXISTS `$eventsTable` (
            `eventID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
            `eventType` VARCHAR(45) NOT NULL COMMENT 'Τύπος του συμβάντος.',
            `eventTitle` VARCHAR(45) NOT NULL COMMENT 'Τίτλος του συμβάντος',
            `eventDescr` VARCHAR(255) NULL COMMENT 'Περιγραφή του συμβάντος.',
            `classroomID` SMALLINT UNSIGNED NOT NULL COMMENT 'Fkey από classrooms',
            `eventStart` DATETIME NOT NULL COMMENT 'Ημερομηνία - ώρα που αρχίζει το συμβάν.',
            `eventEnd` DATETIME NOT NULL COMMENT 'Ημερομηνία - ώρα που τελειώνει το συμβάν.',
            PRIMARY KEY (`eventID`),
            INDEX `fk_wp_utt_events_wp_utt_classrooms1_idx` (`classroomID` ASC),
            CONSTRAINT `fk_wp_utt_events_wp_utt_classrooms1`
            FOREIGN KEY (`classroomID`)
            REFERENCES `$classroomsTable` (`classroomID`)
            ON DELETE RESTRICT
            ON UPDATE CASCADE)
            ENGINE = InnoDB
            DEFAULT CHARACTER SET = utf8
            COLLATE = utf8_general_ci;";
    dbDelta($sql);

    $wpdb->query("CREATE  OR REPLACE VIEW $lessonsView AS
            SELECT
                periodID,
                lessonID,
                semester,
                $lessonsTable.groupID,
                $lessonsTable.classroomID,
                $lessonsTable.teacherID,
                start,
                end,
                groupName,
                $subjectsTable.subjectID,
                $subjectsTable.title AS subjectTitle,
                $subjectsTable.type AS subjectType,
                color,
                $classroomsTable.name AS classroomName,
                $classroomsTable.type AS classroomType,
                surname as teacherSurname,
                $teachersTable.name as teacherName
            FROM
                $lessonsTable,
                $groupsTable,
                $subjectsTable,
                $classroomsTable,
                $teachersTable
            WHERE
                $lessonsTable.groupID = $groupsTable.groupID
                    AND $groupsTable.subjectID = $subjectsTable.subjectID
                    AND $lessonsTable.classroomID = $classroomsTable.classroomID
                    AND $lessonsTable.teacherID = $teachersTable.teacherID;");

}

Related posts

Leave a Reply

1 comment

  1. The problem was that after updating to wordpress 4.2, wordpress was not accepting the greek characters in commends and enum type. I had to make them english.

    I answer in order to help anybody who has the same problem!