使用开发数据库而不是ENV ['DATABASE_URL']在Heroku上使用DataMapper连接?

时间:2012-07-08 06:56:16

标签: postgresql heroku ruby-datamapper

我的问题是,当我将'postgres://postgres:myohmysosecret@localhost/recall'作为完整的数据库连接时,部署到Heroku DataMapper会尝试使用我的数据库连接信息DataMapper.setup(:default, ENV['DATABASE_URL'] || 'postgres://postgres:myohmysosecret@localhost/recall')的这一部分。

这是我的Heroku日志文件:

2012-07-08T06:49:40+00:00 heroku[web.1]: Starting process with command `bundle exec rackup config.ru -p 26035`
2012-07-08T06:49:48+00:00 app[web.1]:   Is the server running on host "localhost" and accepting
2012-07-08T06:49:48+00:00 app[web.1]:   from <internal:prelude>:10:in `synchronize'
2012-07-08T06:49:48+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/data_objects-0.10.8/lib/data_objects/connection.rb:79:in `initialize': could not connect to server: Connection refused (DataObjects::ConnectionError)
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/data_objects-0.10.8/lib/data_objects/pooling.rb:177:in `block in new'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/data_objects-0.10.8/lib/data_objects/pooling.rb:172:in `new'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/data_objects-0.10.8/lib/data_objects/connection.rb:79:in `new'
2012-07-08T06:49:48+00:00 app[web.1]:   TCP/IP connections on port 5432?
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:251:in `open_connection'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/data_objects-0.10.8/lib/data_objects/connection.rb:68:in `new'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/data_objects-0.10.8/lib/data_objects/pooling.rb:119:in `new'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-transactions-1.2.0/lib/dm-transactions/adapters/dm-do-adapter.rb:69:in `open_connection'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:61:in `execute'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-migrations-1.2.0/lib/dm-migrations/adapters/dm-postgres-adapter.rb:60:in `ensure in without_notices'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-migrations-1.2.0/lib/dm-migrations/adapters/dm-postgres-adapter.rb:60:in `without_notices'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-migrations-1.2.0/lib/dm-migrations/adapters/dm-postgres-adapter.rb:18:in `upgrade_model_storage'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-migrations-1.2.0/lib/dm-migrations/auto_migration.rb:73:in `upgrade_model_storage'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-migrations-1.2.0/lib/dm-migrations/auto_migration.rb:47:in `block in repository_execute'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-migrations-1.2.0/lib/dm-migrations/auto_migration.rb:145:in `auto_upgrade!'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/support/descendant_set.rb:64:in `block in each'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `each'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `block in each'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/support/subject_set.rb:210:in `block in each'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `each'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/support/subject_set.rb:210:in `each'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/support/descendant_set.rb:63:in `each'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-migrations-1.2.0/lib/dm-migrations/auto_migration.rb:46:in `repository_execute'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-migrations-1.2.0/lib/dm-migrations/auto_migration.rb:27:in `auto_upgrade!'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/recall.rb:25:in `<top (required)>'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/config.ru:2:in `require'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/config.ru:2:in `block in <main>'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/config.ru:1:in `new'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/config.ru:1:in `<main>'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
2012-07-08
T06:49:48+00:00 app[web.1]:     from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/bin/rackup:4:in `<top (required)>'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:137:in `start'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/bin/rackup:19:in `load'
2012-07-08T06:49:48+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/bin/rackup:19:in `<main>'

1 个答案:

答案 0 :(得分:3)

我遇到了这个问题,最后它似乎与Heroku tutorial上的以下内容有关,但看似错误:

ENV['DATABASE_URL']

基本上,您可能没有数据库。正在运行heroku config会显示此信息。您可以运行以下行为您创建数据库,详细内容为here

heroku addons:add heroku-postgresql:dev

然后再次运行heroku config以获取数据库字符串,或者您可以在DataMapper.setup中使用以下行:

ENV['HEROKU_POSTGRESQL_CYAN_URL']

希望这有帮助!我已将此添加到我自己的Heroku支持票中,看看他们说了什么!