ruby-on-rails - Rails 生产 fatal error : database "db/production.postgresql" does not exist

标签 ruby-on-rails postgresql ubuntu capistrano

我正在关注这个tutorial从 Digitalocean 设置我的 Rails 生产服务器。但是,我在 cap production deploy:initial

处遇到错误

我的设置包括 Ubuntu 14.04、Capistrano、Nginx 和 Digitalocean 中的 Puma。

在教程中,他们没有提到编辑 database.yml,但我注意到我需要编辑它,因为默认数据库是 sqlite3,而我的生产数据库是 postgresql。

SSHKit::Runner::ExecuteError: Exception while executing on host      159.203.107.215: Exception while executing on host 159.203.107.215: rake     exit status: 1
rake stdout: rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  database "db/production.postgresql" does not exist

数据库.yml

default: &default
adapter: postgresql
pool: 5
timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

test:
<<: *default
 database: db/test.sqlite3

production:
<<: *default
database: db/production.postgresql

最佳答案

Sqlite 和 PostgreSQL 需要非常不同的连接参数。 Sqlite 只是采用磁盘数据库文件的路径。 PostgreSQL 需要连接信息:主机名、数据库名称、用户名、密码。我会摆脱你的 default 东西,让每一个都明确。像这样:

development:
  pool: 5
  timeout: 5000
  database: db/development.sqlite3

test:
  pool: 5
  timeout: 5000
  database: db/test.sqlite3

production:
  adapter: postgresql
  pool: 5
  encoding: unicode
  database: your_db_name_here
  host: your_db_host_here
  username: your_db_username_here
  password: your_db_password_here

我还鼓励您不要在此文件中存储实际的用户名和密码,而是通过环境获取它(dot_env gem 和其他几个 gem 可以提供帮助)。像这样:

username: <%= ENV.fetch('DATABASE_USERNAME', '') %>
password: <%= ENV.fetch('DATABASE_PASSWORD', '') %>

关于ruby-on-rails - Rails 生产 fatal error : database "db/production.postgresql" does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33178611/

相关文章:

ruby-on-rails - 如何配置 procfile,sidekiq.yml 以便不同的 sidekiq 队列在 heroku 中的不同 dynos 上运行?

ruby-on-rails - 为什么我会收到此参数错误?

postgresql - Postgres 使用 cp1252 编码?

python-3.x - 与外部 MQTT 代理连接时出现问题

javascript - Rails 中带有 '/' 和 '.' 字符的 select_tag 的 OnChange 问题

ruby-on-rails - 从 ActiveRecord 模型中删除属性

sql - 在 SQL 查询中返回每个组的前 x 个结果

c - 调试 postgresql for where 'A' < 'a'

ubuntu - 如何阻止下划线在 Xubuntu 16.04 的 xvnc4 窗口中的 xterm 中消失?

c - 运行 C 代码时,我在 Ubuntu 虚拟终端中遇到段错误(核心转储),这里我提到了以下代码