Bob
Bob

Reputation: 8714

Knex alter table not adding column

I am writing the migration and the code looks like this

exports.up = async (knex) => {
    knex.schema.alterTable('history', function(table) {
        table.string('someCheck', 20).nullable().defaultTo(null);
    });
};

Once I run node -r dotenv/config ./node_modules/knex/bin/cli.js migrate:up it says that is successful.

Using environment: development
Batch 3 ran the following migrations:
2021051304151_add-check-field.js

And once I check the history table there are no new fields.

Upvotes: 0

Views: 2181

Answers (1)

Mikael Lepistö
Mikael Lepistö

Reputation: 19718

exports.up = async (knex) => {
    return knex.schema.alterTable('history', function(table) {
        table.string('someCheck', 20).nullable().defaultTo(null);
    });
};

or

exports.up = async (knex) => {
    await knex.schema.alterTable('history', function(table) {
        table.string('someCheck', 20).nullable().defaultTo(null);
    });
};

Will work. Now query builder is not executed.

Upvotes: 2

Related Questions