Rails:Postgres + rake db:structure:使用错误的用户转储

时间:2015-08-28 15:48:42

标签: ruby-on-rails postgresql

我试图使用rake' rake db:structure:dump转储我的远程数据库的结构,但每当我运行该命令时,它会忽略我database.yml文件中的用户并使用我本地计算机上的用户,我已登录为。

database.yml中:

 development: &DEFAULT
  adapter: postgresql
  host: remoteaddress.com
  port: 5432
  user: myusername
  password: mypassword
  database: mydatabase

当我运行命令时会发生这种情况:

[~/src/myapp]$ RAILS_ENV=development rbbe rake db:structure:dump --trace                                                                                                                                                                          ✭ git:em-redshift ruby:2.2.0
** Invoke db:structure:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:structure:dump
pg_dump: [archiver (db)] connection to database "mydatabase" failed: FATAL:  password authentication failed for user "emai"
FATAL:  password authentication failed for user "emai"
rake aborted!
Error dumping database
/opt/rubies/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/postgresql_database_tasks.rb:55:in `structure_dump'
/opt/rubies/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:182:in `structure_dump'
/opt/rubies/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:276:in `block (3 levels) in <top (required)>'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/opt/rubies/2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/opt/boxen/rbenv/versions/2.2.0/bin/rake:33:in `<main>'
Tasks: TOP => db:structure:dump

如您所见,它不会将myusername用作用户。而是将其作为我的本地用户(emai)运行。发生了什么事?

P.S。我知道db配置也有效,因为我进入了rails控制台并查询了记录并得到了结果。此外,rake db:schema:dump不会出现身份验证错误。

1 个答案:

答案 0 :(得分:4)

在查看文档(https://github.com/rails/rails/blob/master/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb)后,您需要添加username密钥才能使其正常运行......认真......

 development: &DEFAULT
  adapter: postgresql
  host: remoteaddress.com
  port: 5432
  user: myusername
  username: myusername <-------
  password: mypassword
  database: mydatabase