我正在尝试使用 node.js postgres sql 删除名为
但是我遇到了一个错误。
test
的数据库,但没有成功。var express = require('express');
var app = express();
var pg = require('pg');
var pgp = require('pg-promise')();
// Connect to PostgreSQL database
var connectionString = process.env.DATABASE_URL || 'postgres://postgres:pass123@localhost:5432/test';
var db = pgp(connectionString);
db.connect();
db.query("DROP DATABASE test").then(function()
{
//createDatabases(db);
}).catch(function(err)
{
console.log(err);
});
但是我遇到了一个错误。
{ [error: cannot drop the currently open database]
name: 'error',
length: 87,
severity: 'ERROR',
code: '55006',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'dbcommands.c',
line: '834',
routine: 'dropdb' }
有人知道如何解决这个问题吗?
谢谢
db.connect();
。而且你也不应该在那里包含pg
。 - vitaly-t