使用sequelize cli运行多个命令

时间:2017-05-22 02:10:35

标签: sequelize.js sequelize-cli

我有以下迁移文件,但是我收到此错误:

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');
  }
};

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

1 个答案:

答案 0 :(得分:1)

它与链接查询的方式无关。我遇到了同样的问题并询问了sequelize slack group,结果发现addConstraint将在v4中发布。虽然我认为我们可能已经在文档中看到它并认为它可用。