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

正如您从上面的 table 中看到的那样,在远程计算机 psql 中存在一个名为 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 首先,应用程序将无错误地加载,连接到远程数据库。