Answer the question
In order to leave comments, you need to log in
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'
})
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question