无法为Postgres创建扩展程序

时间:2014-10-07 11:35:57

标签: ruby postgresql postgis

我使用postgres(PostgreSQL)9.3.5使用我的Rails(4.0.1)应用程序和Ruby(2.0.0-p451),其中一个迁移看起来像:

class CreateExtensions< ActiveRecord::Migration
    def up
        connection = ActiveRecord::Base.connection
        extensions = %w(fuzzystrmatch hstore plpgsql postgis postgis_tiger_geocoder postgis_topology)
        ext_query = extensions.map {|e| "CREATE EXTENSION IF NOT EXISTS #{e};" }.join
        connection.execute(ext_query)
    end
end

每当我尝试运行迁移文件时,都会收到以下错误:

CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;CREATE EXTENSION IF NOT EXISTS hstore;CREATE EXTENSION IF NOT EXISTS plpgsql;CREATE EXTENSION IF NOT EXISTS postgis;CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;CREATE EXTENSION IF NOT EXISTS postgis_topology;
PG::UndefinedFile: ERROR:  could not open extension control file "/usr/local/Cellar/postgresql/9.3.5_1/share/postgresql/extension/postgis.control": No such file or directory
: CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;CREATE EXTENSION IF NOT EXISTS hstore;CREATE EXTENSION IF NOT EXISTS plpgsql;CREATE EXTENSION IF NOT EXISTS postgis;CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;CREATE EXTENSION IF NOT EXISTS postgis_topology;
ActiveRecord::StatementInvalid: PG::UndefinedFile: ERROR:  could not open extension control file "/usr/local/Cellar/postgresql/9.3.5_1/share/postgresql/extension/postgis.control": No such file or directory
: CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;CREATE EXTENSION IF NOT EXISTS hstore;CREATE EXTENSION IF NOT EXISTS plpgsql;CREATE EXTENSION IF NOT EXISTS postgis;CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;CREATE EXTENSION IF NOT EXISTS postgis_topology;
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
    from (irb):14
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.1/lib/rails/commands/console.rb:90:in `start'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.1/lib/rails/commands/console.rb:9:in `start'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.1/lib/rails/commands.rb:62:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

我使用Homebrew安装了Postgres,不知道我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

确保从相同的源和兼容版本安装PostgreSQL和PostGIS。