2016-06-14 131 views
0

我正嘗試使用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是安裝在我的服務器上。

+0

安裝在你的服務器的Postgres? '哪個psql'會幫你找到postgresql。 – Emu

+0

我也這麼認爲 - 你想使用postgres和有效的gem,你可能沒有在生產環境中安裝它。 – PatNowak

+1

我相信'postgresql'需要一個與用戶名同名的數據庫,在你的情況下'postgres'存在。首先建立一個名爲'postgres'的數據庫,然後你可以運行'RAILS_ENV = production rake db:create'。 – Dharam

回答

0

感謝@Dharam。

這對我的工作,以及:

I beleive postgresql expects a database with the same name as the user name, in your case postgres , be present. First setup a database with the name postgres then you can run RAILS_ENV=production rake db:create

相關問題