我遇到了使用rails应用程序的问题,很少有人正在研究。我刚刚克隆了repo,并且执行rails db:migrate或尝试访问页面(在服务器运行时)导致此错误:
Started GET "/" for 127.0.0.1 at 2017-06-18 11:58:41 +0100
PG::ConnectionBad (could not connect to server: Cannot assign requested address (0x00002741/10049)
Is the server running on host "0.0.0.0" and accepting
TCP/IP connections on port 6543?
):
pg-0.19.0-x64 (mingw32) lib/pg.rb:45:in 'initialize'
pg-0.19.0-x64 (mingw32) lib/pg.rb:45:in 'new'
pg-0.19.0-x64 (mingw32) lib/pg.rb:45:in 'connect'
activerecord (5.1.1) lib/active_record/connection_adapters/postgresql_adapter.rb:701:in 'connect'
activerecord (5.1.1) lib/active_record/connection_adapters/postgresql_adapter.rb:220:in 'initialize'
activerecord (5.1.1) lib/active_record/connection_adapters/postgresql_adapter.rb:38:in 'new'
activerecord (5.1.1) lib/active_record/connection_adapters/postgresql_adapter.rb:38:in 'postgresql_connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:759:in 'new_connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:803:in 'checkout_new_connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:782:in 'try_to_checkout_new_connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:743:in 'acquire_connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:500:in 'checkout'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in 'connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in 'retrieve_connection'
activerecord (5.1.1) lib/active_record/connection_handling.rb:116:in 'retrieve_connection'
activerecord (5.1.1) lib/active_record/connection_handling.rb:88:in 'connection'
activerecord (5.1.1) lib/active_record/migration.rb:562:in 'connection'
activerecord (5.1.1) lib/active_record/migration.rb:553:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/callbacks.rb:26:in 'block in call'
activesupport (5.1.1) lib/active_support/callbacks.rb:97:in 'run_callbacks'
actionpack (5.1.1) lib/action_dispatch/middleware/callbacks.rb:24:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/executor.rb:12:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:59:in 'call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in 'call_app'
web-console (3.5.1) lib/web_console/middleware.rb:28:in 'block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in 'catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in 'call'
railties (5.1.1) lib/rails/rack/logger.rb:36:in 'call_app'
railties (5.1.1) lib/rails/rack/logger.rb:24:in 'block in call'
activesupport (5.1.1) lib/active_support/tagged_logging.rb:69:in 'block in tagged'
activesupport (5.1.1) lib/active_support/tagged_logging.rb:26:in 'tagged'
activesupport (5.1.1) lib/active_support/tagged_logging.rb:69:in 'tagged'
railties (5.1.1) lib/rails/rack/logger.rb:24:in 'call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/remote_ip.rb:79:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/request_id.rb:25:in 'call'
rack (2.0.3) lib/rack/method_override.rb:22:in 'call'
rack (2.0.3) lib/rack/runtime.rb:22:in 'call'
activesupport (5.1.1) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/executor.rb:12:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/static.rb:125:in 'call'
rack (2.0.3) lib/rack/sendfile.rb:111:in 'call'
railties (5.1.1) lib/rails/engine.rb:522:in 'call'
puma (3.9.1) lib/puma/configuration.rb:224:in 'call'
puma (3.9.1) lib/puma/server.rb:602:in 'handle_request'
puma (3.9.1) lib/puma/server.rb:435:in 'process_client'
puma (3.9.1) lib/puma/server.rb:299:in 'block in run'
puma (3.9.1) lib/puma/thread_pool.rb:120:in 'call'
puma (3.9.1) lib/puma/thread_pool.rb:120:in 'block in spawn_thread'
我已经阅读了类似的问题,所有人都说要重新启动postgres,但是在Windows上它有点乱,所以我重新启动了我的笔记本电脑,它没有解决任何问题。我也试图重新克隆回购。
请注意,其他rails项目确实有效,我认为这与database.yml有关,但我真的不知道该怎么做。 干杯
答案 0 :(得分:2)
确保您的postgresql服务正在运行
确保您创建了可以执行rake db:create
另见database.yml。默认配置是这样的
development:
<<: *default
database: yourappname_development
在那里你还可以添加连接到你的postgres所需的信息,如
port:
username:
password:
hostname:
您可以从另一个正在运行的rails应用程序中获取示例