2014-11-17 48 views
1

我已經在我的控制器SQL語句:Heroku的錯誤PG ::錯誤:錯誤:函數的strftime(未知,無時區的時間戳)不存在

@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 zone) does not exist

我已經註釋掉 config.time_zone = 'UTC'config/application.rb文件,但它沒有工作。

回答

1

您可能想從created_at字段中提取月份,請使用提取sql函數。

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

由於它工作在Heroku上而不是在開發可能是因爲sqlite的劑量不明白「提取」 .. – Sumy

+0

@Sumy,你需要使用PostgreSQL的地方發展,這是不好用不同的數據庫進行開發和生產環境。請參閱這篇文章。 http://stackoverflow.com/questions/10859186/sqlite-in-development-postgresql-in-production-why-not – bhugo313

相關問題