【问题标题】:How to automatically add a column to a Sequelize table?如何自动将列添加到 Sequelize 表?
【发布时间】:2020-12-24 21:05:17
【问题描述】:

我使用node_modules/.bin/sequelize model:create --name Student --attributes firstName:string,email:string 生成了一个模型。现在我想添加一个新列,major。我知道您可以像这样手动创建迁移:

module.exports = {
  up: function(queryInterface, Sequelize) {
    // logic for transforming into the new state
    return queryInterface.addColumn(
      'major',
      'compSci',
     Sequelize.BOOLEAN
    );

  },

  down: function(queryInterface, Sequelize) {
    // logic for reverting the changes
    return queryInterface.removeColumn(
      'major',
      'compSci'
    );
  }
}

是否可以编辑模型并自动创建迁移?所以在 student.js 中添加{major:{type:Sequelize.STRING}},然后生成新的迁移?

【问题讨论】:

    标签: javascript sequelize.js


    【解决方案1】:

    看起来 Sequelize 无法自动生成迁移 source。我将尝试使用 TypeORM,其 github 页面显示它具有自动迁移功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      • 2021-08-08
      • 1970-01-01
      • 2017-02-20
      • 1970-01-01
      相关资源
      最近更新 更多