使用迁移命令创建新 table 时出现 Postgres 错误
Postgres Error when creating a new table using migration command
我正在尝试在我的系统中设置一个 nodeJs 项目。本项目有本地和开发不同的数据库环境,用户名、密码等凭证在knex.js
中添加
我已经在我的本地安装了 Postgres(并使用与我系统相同的用户名和密码)
我需要创建一个新的 table,为此我 运行 使用此命令创建迁移文件
knex migrate:make 'test' --env local --knexfile db/knex.js
文件已创建。然后在这个文件中我添加了代码来创建 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');
};
现在为了在数据库中创建table,我运行这个迁移命令
knex migrate:latest --env local --knexfile db/knex.js
但是我收到这个错误
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)
knex.js文件包含以下部分连接本地数据库的代码
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'
}
},
@escoder,使用以下命令通过 Ubuntu 终端
使用用户名和密码在本地登录 PostgreSQL
psql postgresql://<username>:<password>@localhost:5432
然后,如果您在终端中遇到以下错误
FATAL: password authentication failed for user "postgres"
您必须重置 postgres 用户的密码。
我正在尝试在我的系统中设置一个 nodeJs 项目。本项目有本地和开发不同的数据库环境,用户名、密码等凭证在knex.js
中添加我已经在我的本地安装了 Postgres(并使用与我系统相同的用户名和密码)
我需要创建一个新的 table,为此我 运行 使用此命令创建迁移文件
knex migrate:make 'test' --env local --knexfile db/knex.js
文件已创建。然后在这个文件中我添加了代码来创建 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');
};
现在为了在数据库中创建table,我运行这个迁移命令
knex migrate:latest --env local --knexfile db/knex.js
但是我收到这个错误
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)
knex.js文件包含以下部分连接本地数据库的代码
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'
}
},
@escoder,使用以下命令通过 Ubuntu 终端
使用用户名和密码在本地登录 PostgreSQLpsql postgresql://<username>:<password>@localhost:5432
然后,如果您在终端中遇到以下错误
FATAL: password authentication failed for user "postgres"
您必须重置 postgres 用户的密码。