【发布时间】: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