簡體   English   中英

找不到 Rails 和遠程 Postgres 數據庫

[英]Rails and Remote Postgres Database Not Found

在遠程機器上,我有一個cardano-node ,它連接到一個cardano-db-sync ,它創建一個名為“cexplorer”的 postgress 數據庫。

$ psql cexplorer
psql (13.1 (Ubuntu 13.1-1.pgdg20.04+1), server 12.5 (Ubuntu 12.5-1.pgdg20.04+1))
Type "help" for help.

cexplorer=# \l
                                     List of databases
   Name    |      Owner      | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+-----------------+----------+-------------+-------------+-----------------------
 cexplorer | learnco_project | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 postgres  | postgres        | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 template0 | postgres        | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |                 |          |             |             | postgres=CTc/postgres
 template1 | postgres        | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |                 |          |             |             | postgres=CTc/postgres

現在我想創建一個連接到該數據庫的 Rails 項目。

所以在rails new backend --api我修改了config/dadabase.yml

development:
  <<: *default
  adapter: postgresql
  encoding: utf8
  database: cexplorer
  username: learnco_project
  password: <%= ENV['PG_PWD'] %>
  host: <%= ENV['IP_PG_SERVER'] %>
  port: 5432
  pool: 3 

然后我啟動rails server但是當我訪問http://localhost:3000/我收到以下消息:

FATAL: database "cexplorer" does not exist

正如您在遠程機器psql的上表cexplorer確實存在名為cexplorer的數據庫。

知道我可以更改什么以便找到數據庫嗎?

這是完整的跟蹤:

ActiveRecord::NoDatabaseError
FATAL: database "cexplorer" does not exist
Extracted source (around line #50):
48
49
50
51
52
53
              
    rescue ::PG::Error => error
      if error.message.include?(conn_params[:dbname])
        raise ActiveRecord::NoDatabaseError
      else
        raise
      end

Rails.root: /Users/sergio/Documents/github/learn/front-end/cardano-delegations-slowmo/backend

Application Trace | Framework Trace | Full Trace
activerecord (6.0.3.4) lib/active_record/connection_adapters/postgresql_adapter.rb:50:in `rescue in postgresql_connection'
activerecord (6.0.3.4) lib/active_record/connection_adapters/postgresql_adapter.rb:33:in `postgresql_connection'
activerecord (6.0.3.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
activerecord (6.0.3.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
activerecord (6.0.3.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
activerecord (6.0.3.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
activerecord (6.0.3.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
activerecord (6.0.3.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
activerecord (6.0.3.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
activerecord (6.0.3.4) lib/active_record/connection_handling.rb:221:in `retrieve_connection'
activerecord (6.0.3.4) lib/active_record/connection_handling.rb:189:in `connection'
activerecord (6.0.3.4) lib/active_record/migration.rb:562:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.3.4) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.3.4) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.3.4) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.0.3.4) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.3.4) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.3.4) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.3.4) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.3.4) lib/rails/rack/logger.rb:26:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.3.4) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
railties (6.0.3.4) lib/rails/engine.rb:527:in `call'
puma (4.3.6) lib/puma/configuration.rb:228:in `call'
puma (4.3.6) lib/puma/server.rb:713:in `handle_request'
puma (4.3.6) lib/puma/server.rb:472:in `process_client'
puma (4.3.6) lib/puma/server.rb:328:in `block in run'
puma (4.3.6) lib/puma/thread_pool.rb:134:in `block in spawn_thread'

首先運行rake db:create ,應用程序將無錯誤地加載,並連接到遠程數據庫。

暫無
暫無

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

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