我正在关注这个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/