我正在构建一个 Web 应用程序,当它在生产模式 @Heroku 上运行时崩溃并尝试执行以下查询,而在开发模式下一切运行顺利。
查询如下:
report_id = ReportsNum.group("report_id").
having("GROUP_CONCAT(patent_num ORDER BY patent_num ASC SEPARATOR ',') = ?",patents_list).
order(created_at: :desc).
pluck(:report_id).
first
这是我收到的异常消息:
2014-01-08T18:46:48.316625+00:00 app[web.1]: PG::SyntaxError: ERROR: syntax error at or near "SEPARATOR"
2014-01-08T18:46:48.316633+00:00 app[web.1]: ^
2014-01-08T18:46:48.316637+00:00 app[web.1]: : SELECT "report_patent_nums"."report_id" FROM "report_patent_nums" GROUP BY report_id HAVING GROUP_CONCAT(patent_num ORDER BY patent_num ASC SEPARATOR ',') = 'AB1234567S1,AB1234567S2' ORDER BY "report_patent_nums"."created_at" DESC
2014-01-08T18:46:48.316701+00:00 app[web.1]: LINE 1: ...G GROUP_CONCAT(patent_num ORDER BY patent_num ASC SEPARATOR ...
2014-01-08T18:46:48.316632+00:00 app[web.1]: LINE 1: ...G GROUP_CONCAT(patent_num ORDER BY patent_num ASC SEPARATOR ...
2014-01-08T18:46:48.316703+00:00 app[web.1]:
这可能是什么原因,因为在开发模式下它运行顺利?
以下警告可能是造成这种情况的原因吗?
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
最佳答案
在生产中使用 PostgreSQL 数据库时使用 MySQL 数据库进行开发是一个坏主意(即 Heroku 仅使用 Postgres,除非您使用附加组件)。
MySQL 和 Postgres 之间的 SQL 实现存在显着差异,这将导致难以解决的生产错误。
例如,我认为 Postgres 甚至没有您尝试使用的 GROUP_CONCAT 方法。
在这里查看 Heroku 的建议:
关于ruby-on-rails - PG::SyntaxError: 错误:在 Rails 中的生产模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21004585/