javascript - Sequelize 迁移失败(postgres)

标签 javascript node.js orm database-migration sequelize.js

我正在尝试使用 sequelize 将 postgresql 与我的 Node 应用程序一起使用。但我无法让它发挥作用。当我运行 sequelize -m 时,我得到了这个输出:

Loaded configuration file "config/config.json".
Using environment "development".
Running migrations...
20130916100313-create-table-usuarios.js
Completed in 21ms

events.js:74
        throw TypeError('Uncaught, unspecified "error" event.');
              ^
TypeError: Uncaught, unspecified "error" event.
    at TypeError (<anonymous>)
    at EventEmitter.emit (events.js:74:15)
    at null.<anonymous> (/home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/migrator.js:95:44)
    at EventEmitter.emit (events.js:98:17)
    at module.exports.finish (/home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/query-chainer.js:138:30)
    at exec (/home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/query-chainer.js:92:16)
    at onError (/home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/query-chainer.js:72:11)
    at EventEmitter.emit (events.js:95:17)
    at /home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/migration.js:65:19
    at null.<anonymous> (/home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/emitters/custom-event-emitter.js:52:38)

这是我的 config.json:

{
  "development": {
    "username": "cloudlogger",
    "password": "foobar",
    "database": "cloudlogger_dev",
    "dialect":"postgres",
    "protocol":"postgres",
    "host": "127.0.0.1"
  },
  "test": {
    "username": "cloudlogger",
    "password": "foobar",
    "database": "cloudlogger_test",
    "dialect":"postgres",
    "protocol":"postgres",    
    "host": "127.0.0.1"
  },
  "production": {
    "username": "cloudlogger",
    "password": "foobar",
    "database": "cloudlogger_pro",
    "dialect":"postgres",
    "protocol":"postgres",
    "host": "127.0.0.1"
  }
}

这是 20130916100313-create-table-usuarios.js

module.exports = {
  up: function(migration, DataTypes, done) {
    migration.createTable('Usuario',{
      nombre: {
        type: DataTypes.STRING,
        allowBlank: false,
      },
      username: {
        type: DataTypes.STRING,
        unique: true,
      },
      genero: {
        type:   DataTypes.ENUM,
        values: ['Hombre', 'Mujer']
      },
      email: {
        type: DataTypes.STRING,
        unique: true,
        allowBlank: false,
      },
      password_digest: {
        type: DataTypes.STRING,
        allowBlank: false,
      },
      remember_token: DataTypes.STRING,
      superadministrador: {
        type: DataTypes.BOOLEAN,
        defaultValue: false
      },
      token: DataTypes.STRING,
      fecha_token: {
        type: DataTypes.DATE,
        defaultValue: new Date(0)
      },
      lastLogin: DataTypes.DATE
    }).complete(done);
  },
  down: function(migration, DataTypes, done) {
    migration.dropAllTables().complete(done);
  }
}

编辑

如果我评论或更改此行,我会隔离错误:

      genero: {
        type:   DataTypes.ENUM,
        values: ['Hombre', 'Mujer']
      },

效果不错。好像是ENUM类型的问题

最佳答案

您的 ENUM 语法不正确。它应该是这样的:

type: DataTypes.ENUM('Hombre', 'Mujer')

data types 上查看 sequelize 文档如果您有更多问题

关于javascript - Sequelize 迁移失败(postgres),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18832667/

相关文章:

javascript - 更新 redux 商店上的 isLoading 字段

javascript - 这个 Prototype Ajax 调用的 jQuery 等价物是什么?

Node.js OpsWorks Layer 控制台日志

orm - 多对多关系的 DQL 语句

javascript - 等待所有解析的正确方法

javascript - Backbone 将项目添加到其他项目之间的集合(不插入堆栈)

node.js - 我可以在不使用/安装 node.js/npm 的情况下设置 Angular 6 吗?

javascript - 以编程方式启动 vue-cli-service serve 时控制 webpack 的冗长程度

java - 使用 ebean 或 hibernate 将值插入到一对一映射注释中

mysql - 使用 Sequelize include 子句查询另一个表中没有条目的记录