Heroku 应用程序正在读取 database.yml 文件
据我所知,Heroku 应该自动生成一个database.yml 文件,并忽略本地文件。但是,我看到一个错误,但事实并非如此,并且我对本地 database.yml 的更改正在影响 Heroku 应用程序。这是有问题的,因为我不知道应该如何设置文件的生产部分,以便 Heroku 可以找到正确的数据库。
例如,使用以下内容
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
后跟 db:migration
$:~/Apps/DancingCupid/DancingCupid$ heroku rake --trace db:migrate
吐出,
rake aborted!
unable to open database file
/app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/connection_adapters/sqlite3_adapter.rb:27:in `initialize'
...
根据我发送用于生产的数据库类型,我可能会得到不同的错误。
除了删除应用程序并创建新应用程序之外,还有其他方法可以解决此问题吗?
From what I can gather, Heroku is supposed to generate a database.yml file automatically, and ignore the local one. However, I am seeing an error where that is not true, and my changes to the local database.yml are affecting the Heroku app. This is problematic because I have no idea how I should setup production portion of the file so Heroku can find the right database.
For instance with the following
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
followed by the db:migration
$:~/Apps/DancingCupid/DancingCupid$ heroku rake --trace db:migrate
spits out
rake aborted!
unable to open database file
/app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/connection_adapters/sqlite3_adapter.rb:27:in `initialize'
...
I can get different errors depending on what type of database I sent for production.
Besides deleting the app and making a new one, is there a way to fix this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Heroku 肯定会在推送时重写您的database.yml,因此源代码控制中的内容并不重要。
要确认这一点,请执行
heroku run bash
,这会将您连接到应用程序中的 bash 会话,然后查看cat config\database.yml
,您将看到它们是如何重写的它。Heroku definitely rewrite your database.yml on push so it doesn't matter what is in there in source control.
To confirm this do
heroku run bash
which will connect you to a bash session in your app then look do acat config\database.yml
and you will see how they have rewritten it.从 Rails 4.1 开始,其他答案不再是不正确。
要在 Heroku 服务器上仔细检查 database.yml 的内容,您可以通过
heroku run bash
运行远程 bash,然后通过cat config/database.yml
查看其内容服务器上的内容并与本地进行比较。The other answers are NOT TRUE anymore as of Rails 4.1.
To double-check the contents of your database.yml on the Heroku server, you can run remote bash via
heroku run bash
and thencat config/database.yml
to see its contents on the server and compare with your local one.我不认为你疯了! (但我以为我疯了)
我已经解决这个问题几天了,终于找到了这篇文章:
http://article.gmane.org /gmane.comp.lang.ruby.rails.heroku/1003/match=database+yml
这让我相信也许这根本不是我的代码!
然后我简单地销毁了我的 Heroku 应用程序并创建了一个新应用程序,然后推送到它。突然一切都正常了!我不知道如何、何时或为什么,但我认为有可能覆盖或损坏 Heroku 创建的 database.yml 文件。
希望这有帮助!
I don't think you are insane! ( But I thought I was )
I have been beating my way around this problem for a few days, and finally found this article:
http://article.gmane.org/gmane.comp.lang.ruby.rails.heroku/1003/match=database+yml
It led me to believe that maybe it wasn't my code at all!
I then simply destroyed my heroku app and created a new one, and pushed to it. Suddenly everything works fine! I don't know how or when or why, but I think it is possible to overwrite or corrupt the database.yml file that Heroku creates.
Hope this helps!
尝试从版本控制中删除
database.yml
。最好将database.yml
复制到database.yml.example
中,并将database.yml
添加到您的.gitignore 文件。
这样,当您推送到 Heroku 时,它将没有任何数据库配置可供参考。
您可能也不希望在生产中使用
sqlite3
gem。确保它位于 Gemfile 的开发/测试组中。Try removing
database.yml
from version control. It's good practice to make a copy ofdatabase.yml
into something likedatabase.yml.example
and addingdatabase.yml
to your.gitignore
file.That way when you push to Heroku it won't have any database configuration to refer to.
You probably also don't want the
sqlite3
gem in production. Make sure it's in the development/test groups in your Gemfile.database.yml 不应推送到 Heroku。它将尝试连接到该数据库,超时然后崩溃。
将其添加到您的 .gitignore 中,这样它就不会出现在那里。
database.yml should not be pushed to Heroku. It will try to connect to that database, timeout and then crash.
Add it to your .gitignore so it doesn't get up there.