簡體   English   中英

Ruby 1.9.3-p392和PostgreSQL

[英]Ruby 1.9.3-p392 and PostgreSQL

我使用rails new app_name -d postgresql創建了一個新的Rails應用程序,但我無法使用任何rails命令( rails srails g controller ControllerName等)。 我收到這些錯誤:

/Users/sebkomianos/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in ``initialize': could not connect to server: No such file or directory (PG::Error)

這是我的database.yml文件:

development:
  adapter: postgresql
  encoding: unicode
  database: project_development
  pool: 5
  username: project
  password:`

test:
  adapter: postgresql
  encoding: unicode
  database: project_test
  pool: 5
  username: project
  password:`

production:
  adapter: postgresql
  encoding: unicode
  database: project_production
  pool: 5
  username: project
  password:`

使用標准rails new app_name命令創建rails應用程序並手動更改Gemfile以使用pg gem時,我遇到了完全相同的問題。

幾周前,我在使用ruby2,並且創建的應用程序運行良好。 Rails版本是3.2.13。

有任何想法嗎?

更新:有趣的是(至少對我而言),我已經將應用程序部署到了heroku,並且在那運行良好。 現在,如果我運行rake db:create ,那么本地所有內容似乎都可以正常運行(無需更改database.yml文件中的任何內容)。 也許這使我的問題更清楚了?

您可能需要在config/database.yml中指定socket參數,以指定Postgres UNIX類型套接字的完整路徑。 它可能位於非標准位置。

我通常避免將config/database.yml檢入項目源存儲庫,因為它會導致與使用相同代碼庫且配置不同的其他人發生沖突。 而是將database.yml.example作為有用的模板開始。

添加host: localhost通常具有強制TCP / IP連接的作用,但這可能對您不起作用。 有時可以使用host: 127.0.0.1代替,因為localhost可能被解釋為“使用默認UNIX套接字”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM