gpt4 book ai didi

sqlite - Sinatra 中的 pg sql-lite 适配器出错

转载 作者:行者123 更新时间:2023-11-29 13:35:32 26 4
gpt4 key购买 nike

我在连接到 Sinatra 中的开发数据库时遇到问题。做后端的人在纽约,目前不在。我对前端比较熟悉,想知道是否缺少一些简单的东西?

生产数据库连接正常,但是当我尝试以开发模式启动它时,我在终端中遇到了一堆错误。我也尝试过使用端口 5432 启动 thin,但没有成功。

有什么想法吗? 编辑 在下面添加了 models.rb

终端

mdb|moreButton⚡ ⇒ ruby app.rb   
/Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/connection.rb:79:in `initialize': could not connect to server: Connection refused (DataObjects::ConnectionError)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/connection.rb:79:in `new'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/pooling.rb:181:in `block in new'
from <internal:prelude>:10:in `synchronize'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/pooling.rb:176:in `new'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/pooling.rb:121:in `new'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/connection.rb:68:in `new'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:251:in `open_connection'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-transactions-1.2.0/lib/dm-transactions/adapters/dm-do-adapter.rb:69:in `open_connection'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:33:in `select'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-migrations-1.2.0/lib/dm-migrations/adapters/dm-postgres-adapter.rb:45:in `schema_name'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-migrations-1.2.0/lib/dm-migrations/adapters/dm-do-adapter.rb:26:in `storage_exists?'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-migrations-1.2.0/lib/dm-migrations/auto_migration.rb:65:in `storage_exists?'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-migrations-1.2.0/lib/dm-migrations/auto_migration.rb:120:in `storage_exists?'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-constraints-1.2.0/lib/data_mapper/constraints/migrations/model.rb:22:in `auto_migrate_constraints_down'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-constraints-1.2.0/lib/data_mapper/constraints/migrations/singleton_methods.rb:39:in `block in auto_migrate_constraints_down'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/descendant_set.rb:64:in `block in each'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/subject_set.rb:210:in `block in each'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `block in each'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `each'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `each'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/subject_set.rb:210:in `each'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/descendant_set.rb:63:in `each'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-constraints-1.2.0/lib/data_mapper/constraints/migrations/singleton_methods.rb:38:in `auto_migrate_constraints_down'
from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-constraints-1.2.0/lib/data_mapper/constraints/migrations/singleton_methods.rb:7:in `auto_migrate!'
from /Users/adam/Git/mdb/models.rb:403:in `<top (required)>'
from /Users/adam/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/adam/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from app.rb:1:in `<main>'

我的 gem 集

mdb|moreButton⚡ ⇒ gem list

*** LOCAL GEMS ***

addressable (2.2.8)
backports (2.6.4, 2.6.1)
bcrypt-ruby (3.0.1)
bundler (1.1.5)
daemons (1.1.9)
data_mapper (1.2.0)
data_objects (0.10.10, 0.10.8)
dm-adjust (1.2.0)
dm-aggregates (1.2.0)
dm-constraints (1.2.0)
dm-core (1.2.0)
dm-do-adapter (1.2.0)
dm-migrations (1.2.0)
dm-postgres-adapter (1.2.0)
dm-serializer (1.2.2, 1.2.1)
dm-sqlite-adapter (1.2.0)
dm-timestamps (1.2.0)
dm-transactions (1.2.0)
dm-types (1.2.2, 1.2.1)
dm-validations (1.2.0)
do_postgres (0.10.10, 0.10.8)
do_sqlite3 (0.10.10, 0.10.8)
eventmachine (1.0.0, 0.12.10)
fastercsv (1.5.5)
hpricot (0.8.6)
json (1.7.5, 1.6.7)
json_pure (1.7.5, 1.6.7)
mime-types (1.19)
multi_json (1.3.6, 1.0.4)
multimap (1.1.2)
rack (1.4.1)
rack-protection (1.2.0)
rack-test (0.6.2, 0.6.1)
rake (0.9.2.2)
rest-client (1.6.7)
rubygems-bundler (1.0.3)
rvm (1.11.3.5)
sass (3.2.1)
shotgun (0.9)
sinatra (1.3.3, 1.3.2)
sinatra-contrib (1.3.1)
sinatra-reloader (1.0)
stringex (1.4.0, 1.3.3)
thin (1.5.0)
tilt (1.3.3)
time-ago-in-words (0.1.2)
uuidtools (2.1.3, 2.1.2)

app.rb gem 文件

source 'http://rubygems.org'
gem 'sinatra'
gem 'data_mapper'
gem 'hpricot'
gem 'dm-core'
gem 'json'
gem 'dm-postgres-adapter'
gem 'dm-adjust'
gem 'time-ago-in-words'
gem 'sass'
gem 'rest-client'
gem 'multimap'

group :development do
gem "dm-sqlite-adapter"
gem 'sinatra-reloader'
end

模型.rb

if $development
DataMapper.setup(:default, "postgres://localhost/mistakesdb_default")
else
DataMapper.setup(:default, "postgres://giberish:giberish@ec2-23-21-209-147.compute-1.amazonaws.com:5432/giberish")
end
DataMapper.finalize
if $development
#DataMapper.auto_upgrade!
DataMapper.auto_migrate!
else
DataMapper.auto_upgrade!
#DataMapper.auto_migrate!
end

###### required.rb ######
$development = File.exists?('/Users/adam')

##### Top of app.rb #####
require "./models.rb"
require "./required.rb"
require "sinatra"
require "sass"
require "sinatra/reloader" if $development
require "time-ago-in-words"
require "rest_client"
require "multimap"

最佳答案

在开发模式下,DataMapper 正在尝试连接到名为 mistakesdb_default 的本地 PostgreSQL 数据库。看来您根本没有运行本地 postgres 安装,因此出现“连接被拒绝”错误。根据您的操作系统,您可以在 http://www.enterprisedb.com/ 找到一个简单的 postgres 安装程序。 .

关于sqlite - Sinatra 中的 pg sql-lite 适配器出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13367363/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com