2013-12-10 90 views
1

正如我在標題中提到的,我在Ruby on Rails上使用PostgreSQL數據庫,因爲heroku不再支持MySQLite。在我運行命令rails generate scaffold User name:string email:string後,一切都很順利,但是當我嘗試rake db:migrate時,它拋出了一些錯誤。搜索了一段時間後,我將10.0ke的Rake降爲0.8.7。這是我得到的錯誤 - 跟蹤:Ruby on Rails命令rake db:migrate不能使用PostgreSQL

> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake/alt_system.rb:32: 
> Use RbConfig instead of obsolete and deprecated Config. (in 
> /home/Roma/rails_projects/coise) 
> ** Invoke db:migrate (first_time) 
> ** Invoke environment (first_time) 
> ** Execute environment 
> ** Execute db:migrate rake aborted! could not connect to server: Connection refused 
>   Is the server running on host "localhost" (127.0.0.1) and accepting 
>   TCP/IP connections on port 5432? /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:928:in `initialize' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:928:in `new' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:928:in `connect' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:228:in `initialize' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:25:in 
> `new' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:25:in 
> `postgresql_connection' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in 
> `new_connection' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:238:in 
> `checkout_new_connection' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:194:in 
> `block (2 levels) in checkout' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in 
> `loop' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in 
> `block in checkout' /usr/lib/ruby/1.9.1/monitor.rb:211:in 
> `mon_synchronize' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:189:in 
> `checkout' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in 
> `connection' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:318:in 
> `retrieve_connection' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in `retrieve_connection' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/migration.rb:486:in 
> `initialize' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/migration.rb:433:in 
> `new' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/migration.rb:433:in 
> `up' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/migration.rb:415:in 
> `migrate' 
> /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/railties/databases.rake:142:in 
> `block (2 levels) in <top (required)>' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in 
> execute' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in 
> `each' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in 
> `execute' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in 
> `block in invoke_with_call_chain' 
> /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in 
> `invoke_with_call_chain' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:in 
> `invoke_task' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 
> levels) in top_level' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `each' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block in 
> top_level' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in 
> `standard_exception_handling' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in 
> `top_level' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in `block in 
> run' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in 
> `standard_exception_handling' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run' 
> /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top 
> (required)>' /usr/bin/rake:23:in `load' /usr/bin/rake:23:in `<main>' 

我真的不知道該怎麼做。我還將介紹我的database.yml文件(通過搜索時遇到的提示進行了一些更改):

development: 
    adapter: postgresql 
    encoding: unicode 
    database: coise_development 
    pool: 5 
    username: coise 
    password: 
    host: localhost 
    port: 5432 

test: 
    adapter: postgresql 
    encoding: unicode 
    database: coise_test 
    pool: 5 
    username: coise 
    password: 
    host: localhost 
    port: 5432 

production: 
    adapter: postgresql 
    encoding: unicode 
    database: coise_production 
    pool: 5 
    username: coise 
    password: 
+0

您的posgresql服務器是否正在運行?在Linux中,您可以使用命令'sudo service postgresql start'啓動它。 – usha

+0

我的機器是Windows 7,但是我正在運行Cygwin,我會試試。 –

+0

正如我所想的那樣。服務在Cygwin上不起作用。我確定我使用Cygwin安裝來安裝PostGreSQL,但我不知道如何運行它的命令...... –

回答

1

我已經取得了進展。我可以通過這個StackOverflow post-Enable Postgresql in Cygwin來啓動並運行我的PostGreSql服務。最後,我所要做的就是根據用戶在PostGreSql服務啓動時更改我的database.yml文件用戶名和數據庫字段,在我的情況下是「Roma」。

最後,命令rake db:migrate沒有遇到任何問題,就像我推動heroku一樣,完美無瑕。唯一我仍然不明白的地方在於heroku託管,因爲我的用戶頁面(我使用Rails scaffold命令添加的表格)尚不可用。我的heroku告訴我應該有更多的「Dynos」並升級到「Production Postgresql Database」。我不確定這是否意味着需要一段時間才能完成主機,或者實際上我的應用程序有任何問題,儘管我必須說生成的數據庫非常簡單。如果任何版主認爲這應該變成一個新的StackOverflow帖子,請讓我知道。

相關問題