Search code examples
migrationsequelize.jsdatabase-migrationsequelize-cli

Make Sequelize seed after fields in other columns


Is there any way in Sequelize to add another column and then populate it with the contents of another column(s)?


Solution

  • You can do this using migrations.

    Something like

    queryInterface.addColumn(
      'MyAwesomeTable',
      'myAwesomeColumn',
      {
        type: Sequelize.STRING,
        default: 6
      }
    ).then(() => {
    
       return queryInterface.sequelize.query('UPDATE MyAwesomeTable SET myAwesomeColumn = someOtherColumn')
    })