【问题标题】:Sinatra/ActiveRecord + Heroku generating errorsSinatra/ActiveRecord + Heroku 生成错误
【发布时间】:2012-01-05 14:11:30
【问题描述】:

场景:
我正在使用 Sinatra + Sinatra/Active Record + SQLite3 进行本地开发。我知道当我推送到 Heroku 时,它使用 Postgresql。这很好,因为我使用的是活动记录,我应该没有问题。

APP.RB 文件

require 'rubygems'
require 'sinatra'
require 'sinatra/activerecord'
require 'open-uri'
require 'uri'
require 'nokogiri'

configure :development do
  set :database, 'sqlite://development.db'
end

configure :test do
  set :database, 'sqlite://test.db'
end

configure :production do
  db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/mydb')

  ActiveRecord::Base.establish_connection(
    :adapter  => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
    :host     => db.host,
    :username => db.user,
    :password => db.password,
    :database => db.path[1..-1],
    :encoding => 'utf8'
  )
end

class Picture < ActiveRecord::Base

end

get '/' do
  @test = Picture.find(:all)
  erb :index
end

错误
当我尝试heroku rake db:migrate 时,出现以下错误...

DEBUG -- : NoMethodError: undefined method `values' for #<PGresult:0x00000002b24d08>: SHOW client_min_messages   

DEBUG -- : PGError: ERROR:  invalid value for parameter "client_min_messages": ""

然后我想好吧,不用担心,我会尝试将数据从本地 sqlite3 development.db 推送到我的 heroku 生产数据库的 heroku 功能。所以我做了heroku push:db sqlite://development.db 并且数据成功了。

然后我重新启动了应用程序并推送了进一步的提交,但我无法访问与 ActiveRecord 相关的任何内容。如果我对Picture.find(:all) 进行基本查询,我会得到相同的DEBUG 错误。

是我的configure :production 搞砸了我吗? 有什么建议吗?

【问题讨论】:

  • "我正在使用活动记录,应该没有问题。"您显然还没有阅读关于 SO 的 heroku 问题。安装和开发 PostgreSQL 会好很多。
  • 是的,听起来我将不得不这样做。希望不要太学习另一种 SQL 语言。
  • SQL 就是 SQL。但是 SQLite 不是 SQL。 (MySQL 也不是。目前还没有。)
  • @Catcall:有没有人真正实现了整个标准?不过,您对“我应该没问题”这一点已经死心了。
  • AR 和 PostgreSQL 相处得很好,很多 Rails 应用程序使用 PostgreSQL(包括我的一些)没有问题。

标签: postgresql activerecord configuration heroku sinatra


【解决方案1】:

您设法将配置参数client_min_messages 设置为空字符串。

手册通知here

有效值为DEBUG5、DEBUG4、DEBUG3、DEBUG2、DEBUG1、LOG、NOTICE、 警告、错误、致命和恐慌

您可以在postgresql.conf 或会话中的任何时间设置此参数:

SET client_min_messages = WARNING;

将其重置为postgresql.conf 中定义的默认值:

RESET client_min_messages;

【讨论】:

  • 是的,我不知道我是怎么做到的?我只是想知道我的应用程序是否正在根据我的设置与 Heroku 上的生产数据库通信。
猜你喜欢
  • 2014-07-10
  • 2012-02-05
  • 1970-01-01
  • 1970-01-01
  • 2015-06-23
  • 2016-03-28
  • 2014-07-21
  • 2014-01-30
  • 2013-06-07
相关资源
最近更新 更多