knex migration:latest 无法连接,而 psql 工作正常
knex migration:latest cannot connect while psql works fine
我需要帮助来弄清楚为什么我不能 运行 在我的本地机器上迁移 knex
使用。 knex 似乎在连接到 postgres 数据库时遇到了一些问题。 运行 knex migration:latest
在终端给我这个错误:
⇒ knex migrate:latest
Using environment: development
Error: Unable to acquire a connection
at Client_PG.acquireConnection (/Users/moldot/prjx-albert/server/node_modules/knex/lib/client.js:332:40)
at Runner.ensureConnection (/Users/moldot/prjx-albert/server/node_modules/knex/lib/runner.js:233:24)
at Runner.run (/Users/moldot/prjx-albert/server/node_modules/knex/lib/runner.js:47:42)
at SchemaBuilder.Target.then (/Users/moldot/prjx-albert/server/node_modules/knex/lib/interface.js:39:43)
at Migrator._ensureTable (/Users/moldot/prjx-albert/server/node_modules/knex/lib/migrate/index.js:256:66)
at Migrator._listCompleted (/Users/moldot/prjx-albert/server/node_modules/knex/lib/migrate/index.js:405:17)
我在本地 Macbook 上使用 postgres。这是我的 knexfile:
var PostgressConnectionStringParser = require('pg-connection-string');
module.exports = {
heroku: {
client: 'pg',
connection: process.env.DATABASE_URL,
migrations: {
directory: "migrations",
tableName: "migrations",
},
},
development: {
client: "pg",
host: "localhost",
port: 5432,
username: "moldot",
database: "c_dev",
migrations: {
directory: "migrations",
tableName: "migrations",
},
ssl: true,
},
}
运行 psql
工作正常:
⇒ psql -h localhost -p 5432 -U moldot -d c_dev
psql (10.1, server 9.5.4)
Type "help" for help.
c_dev=#
我 运行 在 knexfile.js 所在的同一目录中执行命令。谢谢!
您的 knexfile 语法无效。您还没有在此处提供 connection
属性。
它应该是这样的:
module.exports = {
heroku: {
client: 'pg',
connection: process.env.DATABASE_URL,
migrations: {
directory: "migrations",
tableName: "migrations"
}
},
development: {
client: "pg",
connection: {
host: "localhost",
port: 5432,
username: "moldot",
database: "c_dev",
},
migrations: {
directory: "migrations",
tableName: "migrations"
}
}
}
我需要帮助来弄清楚为什么我不能 运行 在我的本地机器上迁移 knex
使用。 knex 似乎在连接到 postgres 数据库时遇到了一些问题。 运行 knex migration:latest
在终端给我这个错误:
⇒ knex migrate:latest
Using environment: development
Error: Unable to acquire a connection
at Client_PG.acquireConnection (/Users/moldot/prjx-albert/server/node_modules/knex/lib/client.js:332:40)
at Runner.ensureConnection (/Users/moldot/prjx-albert/server/node_modules/knex/lib/runner.js:233:24)
at Runner.run (/Users/moldot/prjx-albert/server/node_modules/knex/lib/runner.js:47:42)
at SchemaBuilder.Target.then (/Users/moldot/prjx-albert/server/node_modules/knex/lib/interface.js:39:43)
at Migrator._ensureTable (/Users/moldot/prjx-albert/server/node_modules/knex/lib/migrate/index.js:256:66)
at Migrator._listCompleted (/Users/moldot/prjx-albert/server/node_modules/knex/lib/migrate/index.js:405:17)
我在本地 Macbook 上使用 postgres。这是我的 knexfile:
var PostgressConnectionStringParser = require('pg-connection-string');
module.exports = {
heroku: {
client: 'pg',
connection: process.env.DATABASE_URL,
migrations: {
directory: "migrations",
tableName: "migrations",
},
},
development: {
client: "pg",
host: "localhost",
port: 5432,
username: "moldot",
database: "c_dev",
migrations: {
directory: "migrations",
tableName: "migrations",
},
ssl: true,
},
}
运行 psql
工作正常:
⇒ psql -h localhost -p 5432 -U moldot -d c_dev
psql (10.1, server 9.5.4)
Type "help" for help.
c_dev=#
我 运行 在 knexfile.js 所在的同一目录中执行命令。谢谢!
您的 knexfile 语法无效。您还没有在此处提供 connection
属性。
它应该是这样的:
module.exports = {
heroku: {
client: 'pg',
connection: process.env.DATABASE_URL,
migrations: {
directory: "migrations",
tableName: "migrations"
}
},
development: {
client: "pg",
connection: {
host: "localhost",
port: 5432,
username: "moldot",
database: "c_dev",
},
migrations: {
directory: "migrations",
tableName: "migrations"
}
}
}