I am trying to execute multiple migration statements in a single migration file in order to make changes to multiple columns of same table in one go.
I want to know that whether I am doing it in a write way or not or is there a better and more appropriate way to do it:
module.exports = {
up: function(queryInterface, Sequelize, done) {
queryInterface.changeColumn('users', 'name', {
type: Sequelize.STRING,
allowNull: false,
require: true,
unique: true
}).success(function() {
queryInterface.changeColumn('users', 'address', {
type: Sequelize.STRING,
allowNull: false,
require: true,
unique: true
}).success(function() {
queryInterface.changeColumn('users', 'city', {
type: Sequelize.STRING,
allowNull: false,
require: true,
unique: true
}).success(function() {
queryInterface.changeColumn('users', 'state', {
type: Sequelize.STRING,
allowNull: false,
require: true,
defaultValue: "ncjnbcb"
});
done();
});
});
});
}
};
But I face an error which says:
TypeError: undefined is not a function
Since i couldn't find any way of debugging error in migrations, it will be great if someone helps me out in resolving it or if possible, tell about the way as of how can we figure out the errors in a migration.
Your TypeError is probably because you're not returning anything. The docs say that each migration function should return a Promise. No mention of a done
callback.
To that end, try the following:
return Promise.all([
queryInterface.changeColumn...,
queryInterface.changeColumn...
]);