2

我有以下迁移文件,但出现此错误:

TypeError: queryInterface.addConstraint is not a function

谁能告诉我这应该怎么写?

'use strict';
const uuidV4 = require('uuid/v4');

module.exports = {
  up: function (queryInterface, Sequelize) {
    return queryInterface.createTable('app_users', {
      id: {
        type: Sequelize.UUID,
        primaryKey: true,
        defaultValue: function () {
          return uuidV4()
        }
      },
      createdAt: {
        type: Sequelize.DATE,
        allowNull: false
      },
      updatedAt: {
        type: Sequelize.DATE
      },
      email: {
        type: Sequelize.STRING,
        allowNull: false
      },
      disabled: {
        type: Sequelize.BOOLEAN,
        defaultValue: false,
        allowNull: false
      }
    }).then(function () {
      return queryInterface.addConstraint('app_users', ['email'], {
        type: 'unique',
        name: 'unique_email'
      });
    })
  },

  down: function (queryInterface, Sequelize) {
    return queryInterface.dropTable('app_users');
  }
};

续集[节点:7.10.0,CLI:2.7.0,ORM:4.0.0-2]

4

1 回答 1

1

它与链接查询的方式无关。我遇到了同样的问题,并在 sequelize slack 小组上提问,结果发现它将addConstraint在 v4 中发布。尽管我认为我们可能都在文档中看到了它并认为它是可用的。

于 2017-05-31T01:11:41.713 回答