Mino
Mino

Reputation: 635

Postgres and Sequelize - Cannot read property 'name' of undefined

I am trying to change database in a project running fine on MySQL to Postgres.
I receive the following error when running a migration (both with sync and sequelize 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)

I have isolated only this simple model, but I still get the error

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
}

What could be the problem?

Upvotes: 1

Views: 3253

Answers (1)

Mino
Mino

Reputation: 635

I had to change the connection string to this and now it works. Thanks.

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

Upvotes: 1

Related Questions