Heroku 应用程序正在读取 database.yml 文件

发布于 2024-10-27 02:28:33 字数 715 浏览 1 评论 0原文

据我所知,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

多情出卖 2024-11-03 02:28:33

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 a cat config\database.yml and you will see how they have rewritten it.

挽手叙旧 2024-11-03 02:28:33

从 Rails 4.1 开始,其他答案不再是不正确

Rails 4.1.0 时,config/database.yml 将不再被覆盖
检测到 RC1 应用程序。相反,它将与 DATABASE_URL 合并,以便
可以在 config/database.yml 中设置池大小等其他选项。

要在 Heroku 服务器上仔细检查 database.yml 的内容,您可以通过 heroku run bash 运行远程 bash,然后通过 cat config/database.yml 查看其内容服务器上的内容并与本地进行比较。

The other answers are NOT TRUE anymore as of Rails 4.1.

config/database.yml won’t be overwritten anymore when a Rails 4.1.0
RC1 app is detected. Instead, it will be merged with DATABASE_URL so
additional options like pool size can be set in config/database.yml.

To double-check the contents of your database.yml on the Heroku server, you can run remote bash via heroku run bash and then cat config/database.yml to see its contents on the server and compare with your local one.

时光暖心i 2024-11-03 02:28:33

我不认为你疯了! (但我以为我疯了)

我已经解决这个问题几天了,终于找到了这篇文章:
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!

我做我的改变 2024-11-03 02:28:33

尝试从版本控制中删除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 of database.yml into something like database.yml.example and adding database.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.

遗弃M 2024-11-03 02:28:33

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文