2

我正在尝试使用 activerecord-postgis-adapter 将 rails 应用程序部署到 heroku,但是我不断收到此错误。

ruby 2.0.0p0(2013-02-24 修订版 39474)[x86_64-darwin12.3.0]

导轨 3.2.13

$ heroku run rake db:schema:load
Running `rake db:schema:load` attached to terminal... up, run.9233
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
-- create_table("active_admin_comments", {:force=>true})

...

-- create_table("locations", {:force=>true})
rake aborted!
undefined method `spatial' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition:0x007f6051920618>
/app/vendor/bundle/ruby/2.0.0/gems/rgeo-activerecord-0.5.0/lib/rgeo/active_record/common_adapter_elements.rb:107:in `method_missing'
/app/db/schema.rb:85:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_statements.rb:160:in `create_table'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:466:in `block in method_missing'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `block in say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:458:in `method_missing'
/app/db/schema.rb:80:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/schema.rb:50:in `instance_eval'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/schema.rb:50:in `define'
/app/db/schema.rb:14:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `block in load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:402:in `block (3 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
Tasks: TOP => db:schema:load
(See full trace by running task with --trace)
4

4 回答 4

3

作为临时修复,我只是DATABASE_URL通过替换postgres://postgis://如下更改:

heroku config:set DATABASE_URL='postgis://user:password@host.compute-1.amazonaws.com:port/dbname'

这是我发现解决方法的地方:

https://groups.google.com/forum/#!msg/rgeo-users/SDRhEeMZLWc/nue2sFRV6qwJ

我听说它会在备份等方面产生其他问题,根据:

https://github.com/dazuma/activerecord-postgis-adapter/issues/14

于 2013-05-21T00:04:13.497 回答
2

当我切换到unicorn用作我的网络服务器时,这发生在我身上。我发现我必须添加一些特殊的代码才能config/unicorn.rb使其工作:

# in config/unicorn.rb
after_fork do |server, worker|
  if defined?(ActiveRecord::Base)
    config = Rails.application.config.database_configuration[Rails.env]
    config['adapter'] = 'postgis'
    ActiveRecord::Base.establish_connection(config)
  end
end

在这里找到答案:https ://devcenter.heroku.com/articles/postgis

于 2014-03-12T00:20:19.997 回答
1

要解决这个问题,我所要做的就是将我的适配器config/database.yml从“postgresql”更改为“postgis”。

这是我按照教程应该做的,但我忘记了。毕竟一切都很好。

于 2015-01-13T04:14:18.237 回答
1

因此,Heroku Rails 将使用一些 database.yml 参数,但不是全部。对于 Rails 4.1+ https://devcenter.heroku.com/articles/rails-database-connection-behavior#configuring-connections-in-rails-4-1声明适配器被忽略。

https://devcenter.heroku.com/articles/rails-database-connection-behavior#active-record-4-1-escape-valve声明它将接受url(以便您可以将数据库托管在 Heroku 以外的其他地方) . 不需要硬编码,做一个替换。

production: url: <%= ENV.fetch('DATABASE_URL', '').sub(/^postgres/, "postgis") %>

于 2018-08-24T06:28:53.840 回答