Multiple migration statements in a single migration file

I am trying to execute multiple migration statements in a single migration file to make changes to multiple columns of the same table at a time.

I want to know that I am doing this in writing order or not or is there a better and more suitable way to do this:

Migration code

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 encounter an error that reads:

TypeError: undefined is not a function

Since I could not find a way to debug migration errors, it would be great if someone helps me in solving it or, if possible, tell us about how we can calculate errors in migration.

+5
source share
1 answer

Your TypeError is probably because you are not returning anything. docs say that every migration function should return a Promise. The done callback is not mentioned.

To this end, try the following:

 return Promise.all([ queryInterface.changeColumn..., queryInterface.changeColumn... ]); 
+7
source

Source: https://habr.com/ru/post/1235134/


All Articles