在“生产”上运行 rake 任务;并指定环境?
我在 Linode 有一台主机,并尝试在其上运行 Rake 任务,但收到 mySQL 错误,指出无法连接。看起来它认为它正在开发中。我做了一些谷歌搜索,发现我可以做这样的事情:
bundle exec rails c
它加载开发环境,但我无法运行 User.all
,给我一个访问被拒绝的错误。
如果我运行 bundle execrails c RAILS_ENV=product
我会收到错误:
Rails.env=production database is not configured (ActiveRecord::AdapterNotSpecified)
但是,如果我通过网络访问它,一切都会正常。我之前能够运行 rake db:seed ,所以我知道有一些方法可以解决这个问题。
使用生产凭据访问 mySQL 工作正常。
有什么想法吗?
I have a host at Linode and am trying to run a Rake task on it, but I get a mySQL error saying it can't connect. It looks like it thinks it is on dev. I did some Googling and saw that I can do something like this:
bundle exec rails c
It loads the dev environment and I can't run User.all
giving me an access denied error.
If I run bundle exec rails c RAILS_ENV=production
I get the error:
Rails.env=production database is not configured (ActiveRecord::AdapterNotSpecified)
However, if I access it via the web, everything is OK. I was able to run rake db:seed
before so I know that there's some way around this.
Accessing mySQL with the production credentials works fine.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
或者,在开头:
当您将它放在最后时,它认为您将
RAILS_ENV=product
作为参数传递。Try this:
or, at the beginning:
It thinks you're passing
RAILS_ENV=production
as an argument when you put it at the end.如果您想在 Gemfile 中当前包的上下文中运行控制台并确保您正在使用 Gemset,请使用:
If you want to run your console in the context of the current bundle in your Gemfile and ensure you're using your Gemset use:
这对我有用。这取决于您的服务器及其所有依赖项的设置方式:
RAILS_ENV=生产包执行rails控制台
This works for me. It depends on how your server and all its dependencies are set up:
RAILS_ENV=production bundle exec rails console