Sequelize字段必须通过options.field指定错误

Jam*_*Jam 4 mysql orm node.js express sequelize.js

所以我创建了一个表并稍后修改它以添加外键。我按照这个/sf/answers/3319971231/但它给了我一个错误,说

“错误:必须通过 options.fields 指定字段”

我正在使用sequelize ^6.6.5,我的节点版本是14.17.6,下面提供了我的代码

module.exports = {
  up: async (queryInterface, Sequelize) =>
    Promise.all([
      await queryInterface.addColumn('bonus_transactions', 'wallet_id', {
        type: Sequelize.INTEGER.UNSIGNED,
        allowNull: false,
        after: 'order_id'
      }),
      await queryInterface.addConstraint('bonus_transactions', ['wallet_id'], {
        type: 'FOREIGN KEY',
        name: 'FK_bonus_transactions_wallet_id',
        references: {
          table: 'wallets',
          field: 'id'
        },
        onDelete: 'CASCADE'
      })
    ]),
  down: queryInterface => queryInterface.removeColumn('bonus_transactions', 'wallet_id')
Run Code Online (Sandbox Code Playgroud)

这可能是因为续集版本的原因吗?我搜索了 v6 文档,似乎没有任何与此类似的实现。

Ana*_*oly 5

中的字段addConstaint应在fields选项中指示,如下所示:

queryInterface.addConstraint('bonus_transactions',{
        type: 'FOREIGN KEY',
        name: 'FK_bonus_transactions_wallet_id',
        fields: ['wallet_id'], 
        references: {
          table: 'wallets',
          field: 'id'
        },
        onDelete: 'CASCADE'
      })
Run Code Online (Sandbox Code Playgroud)