Reputation: 16192
I am trying to set up a nodeJs project in my system. This project has different database environment for local and development, for which the username, password and other credentials are added in knex.js
I have installed Postgres, in my local (and used the same username and password as that of my system)
I need to create a new table, for that I ran this command to create the migration file
knex migrate:make 'test' --env local --knexfile db/knex.js
A file is created. Then in this file I added the code to create the table
exports.up = function (knex, Promise) {
return knex.schema
.createTable('oxygen', table => {
table.increments('id').primary();
table.string('name').notNull();
});
};
exports.down = function (knex, Promise) {
return knex.schema.dropTable('oxygen');
};
Now in order to create table in the database, I ran this migration command
knex migrate:latest --env local --knexfile db/knex.js
But I am getting this error
Working directory changed to ~/backend/db
Using environment: local
password authentication failed for user "postgres"
error: password authentication failed for user "postgres"
at Connection.parseE (/home/bhavya/backend/node_modules/pg/lib/connection.js:614:13)
at Connection.parseMessage (/home/bhavya/backend/node_modules/pg/lib/connection.js:413:19)
at Socket.<anonymous> (/home/bhavya/backend/node_modules/pg/lib/connection.js:129:22)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at Socket.Readable.push (_stream_readable.js:212:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
The knex.js file includes following part of code for connecting with the local db
local: {
client: 'pg',
useNullAsDefault: true,
migrations: {
directory: './../db/migrations'
},
seeds: {
directory: './../db/seeds'
},
connection: {
host: '127.0.0.1',
user: 'postgres',
password: 'postgres',
database: 'backend'
}
},
Upvotes: 0
Views: 798
Reputation: 56
@escoder, Use the below command to login locally into PostgreSQL by using username and password via Ubuntu terminal
psql postgresql://<username>:<password>@localhost:5432
Then, If you face this below error in your terminal
FATAL: password authentication failed for user "postgres"
you have to reset your password of postgres user.
Upvotes: 1