Postgres和Sequelize - 无法读取undefined的属性'name'

时间:2016-05-10 18:22:48

标签: node.js postgresql sequelize.js sequelize-cli

我正在尝试将MySQL运行良好的项目中的数据库更改为Postgres 运行迁移时我收到以下错误(包括同步和续集db:migrate)。

/myProject/node_modules/pg/lib/connection.js:109
      self.emit(msg.name, msg);
                   ^

TypeError: Cannot read property 'name' of undefined
    at Socket.<anonymous> (/myProject/node_modules/pg/lib/connection.js:109:20)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:172:18)
    at Socket.Readable.push (_stream_readable.js:130:10)
    at TCP.onread (net.js:542:20)

我只隔离了这个简单的模型,但我仍然得到错误

module.exports = (sequelize, DataTypes) => {
  var User = sequelize.define('User', {
    email: {
      type: DataTypes.STRING,
      validate: {
        isEmail: true
      }
    },
    googleId: {
      type: DataTypes.STRING,
      allowNull: false
    }
  }, {
    underscored: true
  })

  return User
}

可能是什么问题?

1 个答案:

答案 0 :(得分:1)

我必须将连接字符串更改为此,现在它可以正常工作。谢谢。

var sequelize = new Sequelize(match[5], match[1], match[2], {
  dialect: 'postgres',
  protocol: 'postgres',
  port: match[4],
  host: match[3],
  logging: false,
  dialectOptions: {
    ssl: true
  }
})