Create a table and add indexes in a single migration with Sequelize

Yes, the methods can be chained. In your case you just perform the addIndex after createTable method

return queryInterface.createTable('Todos', {
    // columns...
}).then(() => queryInterface.addIndex('Todos', ['author_id', 'title']))
.then(() => {
    // perform further operations if needed
});

Leave a Comment