正如我在標題中提到的,我在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:
您的posgresql服務器是否正在運行?在Linux中,您可以使用命令'sudo service postgresql start'啓動它。 – usha
我的機器是Windows 7,但是我正在運行Cygwin,我會試試。 –
正如我所想的那樣。服務在Cygwin上不起作用。我確定我使用Cygwin安裝來安裝PostGreSQL,但我不知道如何運行它的命令...... –