我曾问一个较早的问题,其并未得到任何回复.
基本上我invalid database url
在尝试时会出错heroku db:push
.
我想我可以尝试显式提供数据库URL.
我试过了:
heroku db:push postgres://postgres@localhost/myrailsdb
但这给了错误:
Failed to connect to database: Sequel::DatabaseConnectionError -> PGError fe_sendauth: no password supplied
提供用户名和密码的格式是什么?
试试heroku db:push postgres://username:password@localhost/myrailsdb
.
以下是如何在Ruby脚本中执行此操作:
# Connect to database. uri = URI.parse(ENV['DATABASE_URL']) postgres = PG.connect(uri.hostname, uri.port, nil, nil, uri.path[1..-1], uri.user, uri.password) # List all tables. tables = postgres.exec('SELECT * FROM pg_catalog.pg_tables') tables.num_tuples.times do |i| p tables[i] end
编辑postgresql配置(pg_hba.conf)文件并将"host"类型方法更改为"trust".但请注意,这不安全.
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 md5
重新启动postgresql服务器并重新运行该命令
$ heroku db:push postgres://postgres@localhost/myrailsdb
以下是我的回答:https://stackoverflow.com/a/7667344/181677