我正在开发一个使用PostgreSQL的Rails项目,我希望将数据库登录细节存储在一个文件中,并使用rbenv使用环境变量访问它们。我在运行Ubuntu 16.10。
考虑到下列档案:
pg_hba.conf
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5database.yml
default: &default
adapter: postgresql
encoding: unicode
host: localhost
pool: 5
username: consul
password: <% ENV['CONSUL_DATABASE_PASSWORD'] %>..rbenv vars
SECRET_KEY_BASE=(secret key)
CONSUL_DATABASE_PASSWORD=(database password)当我试图使用rake db:create命令为项目创建数据库时,我会得到以下错误:
fe_sendauth: no password supplied我试着用明文存储密码,但正如你所想象的那样,我不想这么做。
发布于 2017-07-04 07:01:55
将行更改为
password: <%= ENV['CONSUL_DATABASE_PASSWORD'] %><% %>只对内容进行评估
<%= %>计算并将内容插入标记的位置。
有关erb标记What is the difference between <%, <%=, <%# and -%> in ERB in Rails?的更多详细信息,请参阅此答案
发布于 2017-07-04 07:01:34
fe_sendauth:没有提供密码
<% ENV['CONSUL_DATABASE_PASSWORD'] %>应该是
<%= ENV['CONSUL_DATABASE_PASSWORD'] %>发布于 2018-04-02 10:40:48
在我的例子中,问题在于我有破折号,而不是在我的环境变量名中突出,即:
<%= ENV['APP-NAME_DATABASE_PASSWORD'] %>将config/database.yml中的变量名更改为APP_NAME_DATABASE_PASSWORD为我修复了它。
https://stackoverflow.com/questions/44899011
复制相似问题