场景:
我在本地开发中使用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
搞砸我了吗? 有什么建议吗?
“我正在使用活动记录,我应该没有问题。”你显然没有阅读关于SO的heroku问题。对PostgreSQL进行安装和开发会更好。 – 2012-01-05 02:37:52
是啊,开始听起来像我将不得不这样做。希望不要学习另一种SQL语言。 – alenm 2012-01-05 03:24:23
SQL是SQL。但SQLite不是SQL。 (并且MySQL也不是。)还没有。 – 2012-01-05 04:26:59