【问题标题】:undefined method when trying to build db with activerecord-postgis-adapter尝试使用 activerecord-postgis-adapter 构建数据库时未定义的方法
【发布时间】:2013-05-14 16:08:21
【问题描述】:

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

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

Rails 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)

【问题讨论】:

    标签: ruby-on-rails heroku postgis postgresql-9.2


    【解决方案1】:

    作为临时修复,我只是将 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

    【讨论】:

      【解决方案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

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          【解决方案4】:

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

          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") %>

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-05-14
            • 1970-01-01
            • 2019-10-20
            • 2020-10-13
            相关资源
            最近更新 更多