Postgres要求我們在初始設置之外做些什麼額外的事情?例如,bash命令在使用Rails構建應用程序時,Postgres要求我們執行內置SQLite 3的操作嗎?
$ rake db:migrate
在我切換到postgres後不起作用。
到目前爲止,我已經手動輸入 「寶石 'PG'」 中的Gemfile,跑到捆綁安裝PG,交換源碼中的database.yml到PostgreSQL,與創建數據庫:
$ rails generate scaffold Product \
title:string description:text image_url:string price:decimal
(下面的教程)加在遷移文件的東西,當我跑耙分貝:遷移,我得到:
rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:87:in `connection'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:916:in `initialize'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:823:in `new'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:823:in `up'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:801:in `migrate'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
我沒有做的是爲postgres添加userid和密碼。可以導致這個錯誤? – iamabot
您應該首先執行'rake db:setup':如果數據庫尚不存在,這將創建數據庫。但爲了能夠做到這一點,確保數據庫正在運行;) – nathanvda