How to Add, Delete new Columns in Sequelize CLI

后端 未结 7 1843
刺人心
刺人心 2020-12-07 16:43

I\'ve just started using Sequelize and Sequelize CLI

Since it\'s a development time, there are a frequent addition and deletion of columns. What the best the method

相关标签:
7条回答
  • 2020-12-07 17:24

    If you want to add multiple columns to the same table, wrap everything in a Promise.all() and put the columns you'd like to add within an array:

    module.exports = {
      up: (queryInterface, Sequelize) => {
        return Promise.all([
          queryInterface.addColumn(
            'tableName',
            'columnName1',
            {
              type: Sequelize.STRING
            }
          ),
          queryInterface.addColumn(
            'tableName',
            'columnName2',
            {
              type: Sequelize.STRING
            }
          ),
        ]);
      },
    
      down: (queryInterface, Sequelize) => {
        return Promise.all([
          queryInterface.removeColumn('tableName', 'columnName1'),
          queryInterface.removeColumn('tableName', 'columnName2')
        ]);
      }
    };
    
    

    You can have any column type supported by sequelize https://sequelize.readthedocs.io/en/2.0/api/datatypes/

    0 讨论(0)
提交回复
热议问题