无法为Rails应用程序创建生产数据库
问题描述:
我正尝试使用Postgresql在生产模式下为我的Rails应用程序创建数据库。无法为Rails应用程序创建生产数据库
当我运行命令:
$ RAILS_ENV=production rake db:create
我得到以下错误:
FATAL: database "postgres" does not exist
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "host"=>"localhost", "database"=>"provenword", "pool"=>5, "username"=>"postgres", "password"=>"password"}
我可以创建旧的Rails应用,我有一个数据库。但是,只有这个给我这个错误。我怎样才能使这个工作,所以我可以创建数据库并运行应用程序?
宝石文件:
..
gem 'pg'
..
Rails的版本 - 4.2.6
数据库阳明
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
# default: &default
# user: postgres
# password: password
# pool: 5
# timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
adapter: postgresql
encoding: unicode
host: localhost
database: provenword
pool: 5
username: postgres
password: password
PostgreSQL是安装在我的服务器上。
答
感谢@Dharam。
这对我的工作,以及:
I beleive
postgresql
expects a database with the same name as the user name, in your casepostgres
, be present. First setup a database with the namepostgres
then you can runRAILS_ENV=production rake db:create
安装在你的服务器的Postgres? '哪个psql'会帮你找到postgresql。 – Emu
我也这么认为 - 你想使用postgres和有效的gem,你可能没有在生产环境中安装它。 – PatNowak
我相信'postgresql'需要一个与用户名同名的数据库,在你的情况下'postgres'存在。首先建立一个名为'postgres'的数据库,然后你可以运行'RAILS_ENV = production rake db:create'。 – Dharam