3
我有一个应用程序部署在使用postgresql作为数据库的heroku中。我创建将连接到远程MySQL数据库像下面这样的新模式:Heroku:数据库配置没有指定适配器
# other_database.rb(apps/models/)
class OtherDatabase < ActiveRecord::Base
self.abstract_class = true
establish_connection "remote_#{Rails.env}"
end
# other_model.rb(apps/models/)
class OtherModel < OtherDatabase
self.table_name = "users"
end
我还编辑database.yml文件,并添加这些项:
remote_development:
adapter: mysql2
encoding: utf8
reconnect: false
database: app_development
pool: 5
username: root
password:
socket: /var/run/mysqld/mysqld.sock
remote_production:
adapter: mysql2
encoding: utf8
reconnect: true
database: app_production
pool: 40
username: root
password: secretpassword
socket: /var/run/mysqld/mysqld.sock
host: 12.34.56.78
远程数据库使用mysql作为它的数据库。
它工作正常,在我的本地机器,但是当我把它部署到Heroku的,它创建了一个错误页面,让我抬头对Heroku的日志,我发现这一个:
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/connection_specification.rb:52:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/connection_specification.rb:46:in `resolve_string_connection'
我花了几乎所有的时间寻找答案,但无济于事。希望任何人都可以帮助解决这个问题。
TIA。
Eralph
感谢您的快速回复。你如何设置用户名和密码,以及使用环境变量链接的数据库名称? – Eralph
heroku配置:设置DB_USERNAME =用户名DB_PASSWORD =密码然后通过ENV ['DB_USERNAME']和ENV ['DB_PASSWORD']引用它们 –
我会试试这个功能,并会在出现问题时通知您。谢谢。 – Eralph