A
A
Alexander Koshelev2019-08-01 18:19:19
PostgreSQL
Alexander Koshelev, 2019-08-01 18:19:19

How to connect to db in Sequelize postgres?

Good day to all!
I tried to create a connection to the database and create a table in the existing database (I created the database through PGAdmin3), but I got some strange error, Google searches did not help me understand this situation,
here is the code:

const Sequelize = require('sequelize');
const sequelize = new Sequelize("bd_films", "alejandro", "pass", {
  dialect: "postgres",
  host: "127.0.0.1",
  port: "5432",
  schema: "my_schema"
});

const User = sequelize.define('kik', {// kik - название таблицы
  id: {
    type: Sequelize.INTEGER,
    autoIncrement: true,
    primaryKey: true,
    allowNull: false
  },
  email: {
    type: Sequelize.STRING(254),
    allowNull: false
  },
  password: Sequelize.STRING,
}, {
  timestamps: false, // ЛУЧШЕ ВКЛЮЧИТЬ, ПОКАЗЫВАЕТ КОГДА БЫЛ СОЗДАН ОБЪЪЕКТ И КОГДА ОБНОВЛЯЛСЯ
});

sequelize.sync({force: false}).then(()=>{ //force: true - перезаписывает полностью данные таблицы с нуля
    User.create({
    username: 'test3',
    password: 'test3',
    email: 'test3'
  })
})

and here is the error:
Unhandled rejection SequelizeConnectionError: ������������ "alejandro" �� ������ �������� ����������� (�� ������)
at connection.connect.err (C:\Users\Alexander\Desktop\Alejandro\sites\films\node_modules\sequelize\lib\dialects\postgres\c
onnection-manager.js:182 :24)
at Connection.connectingErrorHandler (C:\Users\Alexander\Desktop\Alejandro\sites\films\node_modules\pg\lib\client.js:191:1
4)
at Connection.emit (events.js:189:13 )
at Socket. (C:\Users\Alexander\Desktop\Alejandro\sites\films\node_modules\pg\lib\connection.js:126:12)
at Socket.emit (events.js:189:13)
at addChunk (_stream_readable.js: 284:12)
at readableAddChunk(_stream_readable.js:265:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

Please help me understand this issue!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question