繁体   English   中英

尝试使用activerecord-postgis-adapter构建数据库时使用undefined方法

[英]undefined method when trying to build db with activerecord-postgis-adapter

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

红宝石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)

当我切换为使用unicorn作为Web服务器时,这发生在我身上。 我发现我必须在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

作为临时解决方案,我只是通过将postgres://替换为postgis://来更改DATABASE_URL ,如下所示:

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

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

这是我教程应该做的,但是我却忘记了。 毕竟比一切还好。

因此,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") %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM