'Issue with Knex migration while migrating view

I am not sure whether is it possible to migrate views or not, but this knex migration is failing. Even though I have created schema and migrated tables without getting any error. When I run the command npx knex migrate:latest, the error generated is as follows migration file "20220516152454_create_batch_class_view.js" failed migration failed with error: knex.schema.createView is not a function

I try to create a view from innerjoin of three tables as follows and I am using MySQL as Database.

exports.up = async function (knex) {
    await knex.schema.createView("batchclassview_1", function (view) {
        view.columns(["batchName", "batchId", "learningModeId", "classId", "className", "classStartTime"]);
        view.as(knex("class AS c")
            .SELECT
            (
                "b.batchName",
                "b.id",
                "b.learningModeId",
                "c.id",
                "c.className",
                "c.classDateAndTime"
            )
            .innerJoin("classbatchmapping AS cb", "cb.classId", "c.id")
            .innerJoin("batch AS b", "b.id", "cb.batchID")
            .whereIn("b.uuid", function () {
                this
                    .select("b.uuid")
                    .from("batch as b")
                    .where("b.isDeleted", "=", 0)
            })
        )
    })
};

exports.down = async function (knex) {
    await knex.schema.dropViewIfExists("batchclassview_1");
};


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source