Danilo Sampaio
Danilo Sampaio

Reputation: 77

How to add a column in sequelize migration

i'm trying to create a column using programmatic migration, but nothing happens... here is my migration file contents:

module.exports = {
    up: function(migration, DataTypes, done) {
        migration.addColumn(
            'table',
            'date',
            DataTypes.DATE
        )
        done()
    },
    down: function(migration, DataTypes, done) {
        done()
    }
}

once the file is created, the following code runs:

var migrator = sequelize.getMigrator({
    path: '/my/migrations/directory'
})

migrator.migrate().success(function() {
    console.log('migration done.');
});

no error occurs, but the 'date' column is not created, and this message is printed in console:

There are no pending migrations.
migration done.

what am i doing wrong?

P.S. do i have to create the config.json for programmatic migration?

Upvotes: 0

Views: 887

Answers (1)

Jan Aagaard Meier
Jan Aagaard Meier

Reputation: 28788

Adding a column is an async operation, you have to wait for it to complete before calling done

addColumn().success(done) 

Upvotes: 1

Related Questions