带循环的 Heroku 数据库 rake
我正在尝试在 heroku 上运行此迁移,但它挂在循环中。
puts "0"
add_column :batches, :store_id, :integer
add_column :batches, :company_id, :integer
puts "1"
for batch in Batch.all()
puts "2"
batch.company_id = batch.register.store.company.id.to_i
puts "3"
batch.store_id = batch.register.store.id.to_i
puts "4"
batch.save
puts "5"
end
puts "6"
不幸的是,我无法确切地知道它挂在哪里,因为我的“放置”都没有显示在控制台中。我得到的最后一行是:
-- add_column(:batches, :store_id, :integer)
我无法通过在heroku上运行的循环进行任何迁移,但它们在本地都工作正常,我做错了什么吗?
Heroku 日志的输出:
2011-06-20T13:58:15+00:00 app[rake.14]: Starting process with command `rake db:migrate --trace`
2011-06-20T13:58:48+00:00 heroku[web.1]: Stopping process with SIGTERM
2011-06-20T13:58:48+00:00 app[web.1]: >> Stopping ...
2011-06-20T13:58:48+00:00 heroku[web.1]: Process exited
I am trying to run this migration on heroku, but it hangs at the loop.
puts "0"
add_column :batches, :store_id, :integer
add_column :batches, :company_id, :integer
puts "1"
for batch in Batch.all()
puts "2"
batch.company_id = batch.register.store.company.id.to_i
puts "3"
batch.store_id = batch.register.store.id.to_i
puts "4"
batch.save
puts "5"
end
puts "6"
Unfortunately, I can't tell exactly where it is hanging because none of my "puts" are being shown in console. The last line I get is:
-- add_column(:batches, :store_id, :integer)
I am not able to get any migrations with a loop working on heroku, but they all work fine locally, am I doing something wrong?
Output from heroku logs:
2011-06-20T13:58:15+00:00 app[rake.14]: Starting process with command `rake db:migrate --trace`
2011-06-20T13:58:48+00:00 heroku[web.1]: Stopping process with SIGTERM
2011-06-20T13:58:48+00:00 app[web.1]: >> Stopping ...
2011-06-20T13:58:48+00:00 heroku[web.1]: Process exited
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能是因为您没有包括我在下面显示的环境;你也可以在heroku控制台中运行它
在你的应用程序shell/终端
然后将其作为一个块运行,因为heroku不会让你运行do/end块
所以这应该在控制台中工作,除非这些字段之一为零,这就是为什么你需要一个 rake 任务来处理错误。
试试这个:
lib/tasks/add_bathces.rake
The problem is probably because you are not including the environment which I show below; you can also run this in heroku console
In your apps shell/terminal
Then just run it as a block because heroku will not let you run do/end blocks
So that should work in console unless one of those fields is nill and that is why you are going to need a rake task for erros.
Try this instead:
lib/tasks/add_bathces.rake