forge->addField([ 'id' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true, ], 'class_id' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, ], 'subject_id' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, ], 'teacher_name' => [ 'type' => 'VARCHAR', 'constraint' => '255', ], 'day_of_week' => [ 'type' => 'TINYINT', 'constraint' => 1, 'comment' => '1=Monday, 7=Sunday', ], 'start_time' => [ 'type' => 'TIME', ], 'end_time' => [ 'type' => 'TIME', ], 'room' => [ 'type' => 'VARCHAR', 'constraint' => '100', 'null' => true, ], 'created_at' => [ 'type' => 'DATETIME', 'null' => true, ], 'updated_at' => [ 'type' => 'DATETIME', 'null' => true, ], ]); $this->forge->addKey('id', true); $this->forge->addKey(['class_id', 'day_of_week']); $this->forge->addForeignKey('class_id', 'classes', 'id', 'CASCADE', 'CASCADE'); $this->forge->addForeignKey('subject_id', 'subjects', 'id', 'CASCADE', 'CASCADE'); $this->forge->createTable('schedules'); } public function down() { $this->forge->dropTable('schedules'); } }