For example, I have db with table Users, which have some fields: (id, username). Some later I decided add new field - email. Of course, I update model, migration and run sequelize db:migration. But nothing happened. Any ideas how to add it in Users?
Asked
Active
Viewed 3,990 times
1 Answers
2
Marat, if you change a migration file you had already ran into table within the database, you won't see the modifications, you have to create a new migrations file in which you're going to make references of the new field you want to create and in which table do you wanna it to be. like this for example. I decided that I need a status field in my Campaigns tables, so this is the right way to do it! hope it helps!
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn('Campaigns', 'status', {
type: Sequelize.ENUM,
values: ['Active', 'Inactive', 'Deleted'],
defaultValue: 'Active',
allowNull: false,
validate: {
notEmpty: true
},
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.removeColumn('Campaigns', 'status');
}
};

Alejandro Olaria
- 43
- 1
- 7
-
Thanks, Alejandro! And after that I find solution for squashing migrations, very useful thing for your suggestion – Marat Kruglov May 28 '18 at 15:04