【问题标题】:unable to migrate database on production while running rake task运行 rake 任务时无法在生产环境中迁移数据库
【发布时间】:2015-07-21 06:43:29
【问题描述】:

我正在开发一个小应用程序,它将 每天下载一个csv文件(从给定的url)并将数据(在csv文件中)注入数据库并在webview中加载相同的数据。它在我的本地系统中运行完美。但是当我从 csv 文件部署到 heroku 数据库注入时不起作用。

这是我的代码。

downloader.rake 文件

namespace :downloader do
desc "download a file"
task:downloading => :environment do
Rails.logger.info("message from task")
Download.destroy_all
ActiveRecord::Base.connection.execute("DELETE from sqlite_sequence where name = 'downloads'")
#**********some other code ************
end
end

schedule.rb 文件

set :environment, 'production'

every 1.minutes do
rake "downloader:downloading"
end

当我在生产中运行它时,它会显示在 log($tail -f log/production.log)

D, [2015-07-21T12:17:02.910529 #11740] DEBUG -- :   Download Load (0.2ms)  SELECT "downloads".* FROM "downloads"
E, [2015-07-21T12:17:02.910635 #11740] ERROR -- : SQLite3::SQLException: no such table: downloads: SELECT "downloads".* FROM "downloads"

【问题讨论】:

  • 你试过heroku rake db:migrate(请检查命令)吗?在 heroku 上迁移数据时会抛出什么错误?
  • 它工作正常..没有显示任何错误..

标签: sql ruby-on-rails heroku rake scheduled-tasks


【解决方案1】:

看起来您的数据库在 Heroku 上还没有准备好。

请确认已为您的应用程序安装了 mysql 数据库,然后运行 ​​heroku run db:setup 来构建架构并为其播种。

【讨论】:

  • 当我运行 heroku run rake db:setup 时,它显示 FATAL: permission denied for database "postgres" DETAIL: User does not have CONNECT privilege.
  • 你使用的是sqllite还是postgresl?无论如何,您是否在 heroku 上为您的应用程序安装了数据库? heroku addons:create heroku-postgresql:hobby-dev
  • 也许heroku pg:reset DATABASE_URL
  • 如果你运行heroku run rake db:schema:load会怎样?
  • 我的意思是 "DELETE from sqlite_sequence where name = 'downloads'" 在 postgres 中显然不起作用
猜你喜欢
  • 1970-01-01
  • 2017-12-20
  • 1970-01-01
  • 1970-01-01
  • 2019-10-28
  • 2012-12-26
  • 1970-01-01
  • 1970-01-01
  • 2012-11-20
相关资源
最近更新 更多