2015-04-05 32 views
-1

我剛剛在rails應用上創建了我的第一個ruby,並且想將我的數據庫更改爲postgresql以便與heroku一起使用它。到目前爲止,我已經完成了這項工作,但我認爲它不能正常工作。如果您發現任何問題,請告訴我嗎?由於正在爲postgresql更改database.yml

的database.yml:

# SQLite version 3.x 
# gem install sqlite3 
# 
# Ensure the SQLite 3 gem is defined in your Gemfile 
# gem 'sqlite3' 
# 
default: &default 
    adapter: postgresql 
    database: myrubyblog 
    user: myrubyblog 
    password: 
    pool: 5 
    timeout: 5000 

development: 
    <<: *default 
    adapter: postgresql 
    database: myrubyblog 
    user: myrubyblog 
    password: 

# 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 
    adapter: postgresql 
    database: myrubyblog 
    user: myrubyblog 
    password: 

production: 
    <<: *default 
    adapter: postgresql 
    database: myrubyblog 
    user: myrubyblog 
    password: 

我也改變了創業板的sqlite3'到寶石 'PG' 中的Gemfile

+1

這可能幫助,如果你能在擴大「但我認爲這是不正常」 ... – 2015-04-05 15:41:28

回答

3

下面應該工作(假定用戶&密碼是正確的Postgres )

default: &default 
    adapter: postgresql 
    user: myrubyblog 
    password: 
    pool: 5 
    timeout: 5000 

development: 
    <<: *default 
    database: myrubyblog 

test: 
    <<: *default 
    database: myrubyblog 

What do the &,<<, * mean in this database.yml file?如何&default重新用於每個數據庫定義的。

您不需要在您的database.yml中定義生產環境; heroku將創建自己的版本database.yml用於生產。

關於配置在database.yml中

詳情運行rails new myblogapp --database=postgresql將創建一個新的myblogapp應用與database.yml定製與Postgres的使用適當的內容見http://edgeguides.rubyonrails.org/configuring.html#configuring-a-database

相關問題