Ruby on rails 为什么Rails显然在更改我的数据库密码?

Ruby on rails 为什么Rails显然在更改我的数据库密码?,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,我真的不明白这里发生了什么。。。这是一场噩梦 我在rails应用程序的database.yml中有以下内容 development: adapter: postgresql encoding: unicode database: segnalazioni_dev pool: 5 username: postgres password: 04210 port: 5432 timeout: 5000 但是当我使用rake db:create时,我得到一个身份验证错误

我真的不明白这里发生了什么。。。这是一场噩梦

我在rails应用程序的database.yml中有以下内容

development:
  adapter: postgresql
  encoding: unicode
  database: segnalazioni_dev
  pool: 5
  username: postgres
  password: 04210
  port: 5432
  timeout: 5000
但是当我使用
rake db:create
时,我得到一个身份验证错误,其中使用的密码与
04210
不同:

    Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", 
"database"=>"segnalazioni_test", "pool"=>5, "username"=>"postgres", 
"password"=>2184, "port"=>5432, "timeout"=>5000}

如您所见,密码已从
04210
更改为
2184
。我尝试将其他密码放入database.yml文件中,只要它们不是以0开头,它们就可以在rake db命令中使用,这是应该的。但是我的postgres用户的密码是04210,我需要用那个

线索不在数据库名称中吗?看起来您运行的是测试而不是开发,不是吗?

这是因为您使用的是数字
04210
,而不是字符串
“04210”
。YAML解释器正在读取“04210”作为八进制值,,因此显示“2184”

要解决此问题,请选择一个不以零开头的数字密码,或者更改database.yml以使用字符串:

development:
  adapter: postgresql
  encoding: unicode
  database: segnalazioni_dev
  pool: 5
  username: postgres
  password: "04210"              # Now it's a string instead of a number.
  port: 5432
  timeout: 5000