如何配置database.yml以部署到Heroku [英] How to configure database.yml for deployment to Heroku
问题描述
我最近升级到最新版本的Rails,我不明白如何将应用程序部署到Heroku。
I recently upgraded to the newest version of Rails, and I don't understand how to deploy applications to Heroku.
这是我的 database.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.sqlite3
我从未在database.yml中看到这种语法。有没有人知道如何配置这个?
I have never seen this syntax before in database.yml. Does anyone know how to configure this?
它看起来和我以前很不一样
It looks a lot different than what I'm used to
development:
adapter: mysql2
encoding: utf8
database: my_app_development
pool: 5
username: root
password:
test:
adapter: mysql2
encoding: utf8
database: my_app_test
pool: 5
username: root
password:
production:
adapter: mysql2
encoding: utf8
database: ymca_gym_production
pool: 5
username: root
password:
感谢
推荐答案
对于Heroku,你将不得不使用postgresql,因为它不支持mysql2。 Heroku有自己的机制来处理数据库,您可以在这里阅读更多: https://devcenter.heroku .com / articles / heroku-postgresql
For Heroku you will have to use postgresql as it doesn't support mysql2. Heroku has its own mechanism to handle databases which you can read more about here: https://devcenter.heroku.com/articles/heroku-postgresql
本质上,将heroku的数据库和您在此文件中定义的本地数据库完全不同。在本地和测试环境中使用sqlite更容易,对于生产,你应该将yaml代码更改为:
Essentially, treat "heroku's databases" and local databases that you define in this file completely different. It will be easier for you to use sqlite for local and test environments and for production you should change your yaml code to this :
development:
adapter: mysql2
encoding: utf8
database: my_app_development
pool: 5
username: root
password:
test:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
production:
adapter: postgresql
database: my_database_production
pool: 5
timeout: 5000
<上面的代码还不足以让它在heroku上工作,你还需要编辑gemfile内容,如下所示:
Above code is not enough to get it working on heroku yet, you will also need to edit the gemfile content like below :
gem 'pg', :group => :production
gem 'mysql2' , :group => :development
gem 'sqlite3', :group => :test
我根据我写的database.yaml代码创建了gemfile代码。您可以将mysql2用于开发和测试环境。如果你这样做,你可以改变gemfile内容如下:
I have made the gemfile code according to the database.yaml code that i wrote. You can use mysql2 for both development and test environment. If you are doing so you can change the gemfile contents like below:
gem 'pg', :group => :production
gem 'mysql2' , :group => [:development, :test]
希望这有助于...:)
Hope this helps.. :)
这篇关于如何配置database.yml以部署到Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!