耙中止PG :: ConnectionBad:致命:数据库“无用”不存在

时间:2019-08-21 19:22:37

标签: ruby-on-rails ruby postgresql vagrant vagrantfile

如何使用rake db:migrate用户对数据库postgres运行my_db。已创建角色postgresmy_db数据库,但是当尝试运行migration命令时,它将引发错误。如果缺少任何步骤,请通知我。我不想使用vagrant用户和vagrant database

vagrant@vagrant-ubuntu-trusty-64:/vagrant$ vagrant ssh
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ psql -h localhost -d my_db -U postgres
my_db=#\q
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ rake db:migrate
vagrant@vagrant-ubuntu-trusty-64:/vagrant$rake db:migrate
rake aborted!
PG::ConnectionBad: FATAL:  database "vagrant" does not exist
                         List of roles
-----------+------------------------------------------------+----------
postgres  | Superuser, Create role, Create DB, Replication | {}
                    List of databases
-----------+----------+----------+-------------+-------------+---------
 my_db      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |

1 个答案:

答案 0 :(得分:0)

您可以通过config/database.yml设置数据库配置。如果您要在两种环境(developmenttest)上都使用PG,它看起来可能像这样:

default: &default
  adapter: postgresql
  encoding: unicode
  host: localhost

development:
  <<: *default
  database: my_db
  username: postgres
  password: PASSWORD

test:
  <<: *default
  database: my_db_test
  username: postgres
  password: PASSWORD

文档:Configuring a postgresql database