Table of Content
How to Add New Fields to Existing Sequelize Migration
Last modified: April 30, 2022- Add a personId fields and make it foreign key to Users table.
'use strict';
module.exports = {
async up (queryInterface, Sequelize) {
return Promise.all([
queryInterface.addColumn(
'Users', // table name
'personId', // new field name
{
type: Sequelize.INTEGER,
references:{
model:'Users',
key:'id'
}
},
),
]);
},
async down (queryInterface, Sequelize) {
return Promise.all([
queryInterface.removeColumn('Users', 'personId'),
]);
}
};