我必须连接到旧数据库才能将数据导入我的新系统,这不是我以前做过的事情,所以我很感激有人帮助我理解我在某处出错的设置。
从命令行我可以轻松连接到旧数据库,无需密码:
$ /usr/local/bin/psql -V
psql (PostgreSQL) 9.2.4
$ /usr/local/bin/psql -U adminuser -p 15432 legacydb
psql (9.2.4, server 8.4.5)
WARNING: psql version 9.2, server version 8.4.
Some psql features might not work.
Type "help" for help.
legacydb=# select count(*) from atable;
count
-------
1005
(1 row)
legacydb=# \q
$
所以在我的 Rails 应用程序中,我以这种方式定义了 app/models/atable.rb:
class Atable < ActiveRecord::Base
establish_connection(
:adapter => "postgresql",
:host => "localhost",
:port => 15432,
:username => "adminuser",
:database => "legacydb"
)
end
但是,当我尝试检索某些内容时,我会收到无密码错误:
rails c
Loading development environment (Rails 4.0.0)
2.0.0-p247 :002 > t = Atable.first
PG::ConnectionBad: fe_sendauth: no password supplied
我的错误是什么?