【问题标题】:heroku error PG::Error: ERROR: function strftime(unknown, timestamp without time zone) does not exist [duplicate]heroku错误PG ::错误:错误:函数strftime(未知,没有时区的时间戳)不存在[重复]
【发布时间】:2014-11-17 18:44:29
【问题描述】:

我的控制器中有以下 sql:

@tot_expense = Expense.where("strftime('%m', created_at) + 0 = ?", Time.now.strftime("%m").to_i).sum("amount")

这在我的开发环境中运行良好。但是在 heroku 中部署后,它在保存记录时给了我以下错误。

PG::Error: ERROR: function strftime(unknown, timestamp without time 区域)不存在

我没有评论 config.time_zone = 'UTC' 在我的 config/application.rb 文件中,但它不起作用。

【问题讨论】:

    标签: ruby-on-rails heroku


    【解决方案1】:

    您可能想从 created_at 字段中提取月份,请使用提取 sql 函数。

      @tot_expense = Expense.where("extract(month from created_at) + 0 = ?", Time.now.strftime("%m").to_i).sum("amount")
    

    【讨论】:

    • 感谢它在 heroku 上工作,但在开发中没有工作,可能是因为 sqlite 不理解“提取”..
    • @Sumy,本地开发需要使用PostgreSQL,开发和生产环境使用不同的数据库不好。请参考这篇文章。 stackoverflow.com/questions/10859186/…
    猜你喜欢
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多