如何使用rake db:migrate
用户对数据库postgres
运行my_db
。已创建角色postgres
和my_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 |
答案 0 :(得分:0)
您可以通过config/database.yml
设置数据库配置。如果您要在两种环境(development
和test
)上都使用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