2012-01-05 36 views
0

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

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": "" 

后来我想确定没有后顾之忧我会试试这个heroku功能,将我的本地sqlite3 development.db中的数据推送到我的heroku制作数据库中。所以,我没有heroku push:db sqlite://development.db成功的数据是。

我然后重新启动应用程序,并进一步推提交,但我不能访问任何与ActiveRecord的。如果我对Picture.find(:all)进行基本查询,则会得到相同的DEBUG错误。我的configure :production搞砸我了吗? 有什么建议吗?

+2

“我正在使用活动记录,我应该没有问题。”你显然没有阅读关于SO的heroku问题。对PostgreSQL进行安装和开发会更好。 – 2012-01-05 02:37:52

+0

是啊,开始听起来像我将不得不这样做。希望不要学习另一种SQL语言。 – alenm 2012-01-05 03:24:23

+0

SQL是SQL。但SQLite不是SQL。 (并且MySQL也不是。)还没有。 – 2012-01-05 04:26:59

回答

1

你以某种方式设置配置参数client_min_messages为空字符串。

手册告知here

有效值DEBUG5,DEBUG4,DEBUG3,DEBUG2,DEBUG1,LOG,通知, WARNING,ERROR,FATAL,和恐慌

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

SET client_min_messages = WARNING; 

要将其重置为默认定义于postgresql.conf

RESET client_min_messages; 
+0

是的,我不知道我是怎么做到的?我只是想知道我的应用程序是否甚至可以根据我的设置与Heroku上的制作数据库进行交流。 – alenm 2012-01-05 03:22:55