无法rake db:setup

时间:2014-01-08 21:12:35

标签: ruby-on-rails

尝试使用Postgres在rails项目上设置一个小练习ruby。

如果有人想知道我正在关注的内容,请点击以下链接:https://www.digitalocean.com/community/articles/how-to-setup-ruby-on-rails-with-postgres

问题在于,每当我尝试rake db:migraterake db:setup时,我都会收到此错误:(这已经缩短到了这一点)

rake aborted!
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"?

我目前的Postgress版本为psql (PostgreSQL) 9.3.2

通过Homebrew的路径是:/usr/local/bin/psql根据此链接是正确的:Repairing Postgresql after upgrading to OSX 10.7 Lion

另外,这是我的bash信息:

export PATH=/usr/local/bin:$PATH
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"

我需要包含任何其他信息才能使其正常工作吗?

谢谢。

修改

# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On OS X with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
development:
  adapter: postgresql
  encoding: unicode
  database: myapp_development
  pool: 5
  username: myapp
  password:

 # Connect on a TCP socket. Omitted by default since the client uses a
 # domain socket that doesn't need configuration. Windows does not have
 # domain sockets, so uncomment these lines.
 #host: localhost

 # The TCP port the server listens on. Defaults to 5432.
 # If your server runs on a different port number, change accordingly.
 #port: 5432

 # Schema search path. The server defaults to $user,public
 #schema_search_path: myapp,sharedapp,public

 # Minimum log levels, in increasing order:
 #   debug5, debug4, debug3, debug2, debug1,
 #   log, notice, warning, error, fatal, and panic
 # Defaults to warning.
  #min_messages: notice

 # 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:
     adapter: postgresql
     encoding: unicode
     database: myapp_test
     pool: 5
     username: myapp
    password:

   production:
     adapter: postgresql
     encoding: unicode
     database: myapp_production
     pool: 5
     username: myapp
    password:

2 个答案:

答案 0 :(得分:3)

Is the server running locally

确保您已启动postgres服务器并使其运行。如果您使用的是Mac,最简单的方法是使用Postgres.app:postgresapp.com

默认情况下,服务器将在端口5432上运行。

另外,确保数据库配置中包含localhost

development:
  adapter: postgresql
  encoding: unicode
  database: myapp_development
  host: localhost

usernamepassword可以省略。

答案 1 :(得分:0)

你可能需要启动你的postgres服务器。

以下是postgres关于如何启动服务器的官方文档。

http://www.postgresql.org/docs/9.3/static/server-start.html

此外,请确保您已为应用创建了适当的用户和数据库。 如果您按照与信件相关联的教程进行操作,那么您将拥有一个密码为myapp的用户password1