【问题标题】:Travis ci, Rails and Postgresql - ERROR type hstore does not existTravis ci、Rails 和 Postgresql - 错误类型 hstore 不存在
【发布时间】:2017-09-02 20:12:57
【问题描述】:

我明白了:

PG::UndefinedObject: ERROR:  type "hstore" does not exist
LINE 1: ...arying(255), "finish" timestamp, "widget_locations" hstore) 

下面是我的 Travis 配置文件:

language: ruby
rvm:
  - 2.0.0
env:
  - DB=postgresql
script: 
  - RAILS_ENV=test bundle exec rake db:migrate --trace
  - bundle exec rake db:test:prepare
  - bundle exec rspec spec/
before_script:
  - cp config/database.travis.yml config/database.yml
  - psql -c 'create database virtual_test' -U postgres
  - psql virtual_test -c 'CREATE EXTENSION hstore' -U postgres
bundler_args: --binstubs=./bundler_stubs
before_install:
  - bundle update debugger-ruby_core_source

我还有以下迁移文件:

class SetupHstore < ActiveRecord::Migration
  def self.up
    execute 'CREATE EXTENSION IF NOT EXISTS hstore'
  end
  def self.down
    execute 'DROP EXTENSION IF EXISTS hstore'
  end
end

无论如何,这都会产生错误。

这里有什么问题吗?

【问题讨论】:

  • 请尝试从psql 控制台启用hstoreCREATE EXTENSION hstore
  • 我已经有before_script 命令` - psql virtual_test -c 'CREATE EXTENSION hstore' -U postgres` 可以吗?

标签: ruby-on-rails ruby postgresql ruby-on-rails-4 travis-ci


【解决方案1】:

可能为时已晚,但遇到了同样的问题。将 hstore create 更改为:

 - psql virtual_test -c 'CREATE EXTENSION IF NOT EXISTS hstore' -U postgres

然后 rake db:test:prepare to this:

 - RAILS_ENV=test bundle exec rake db:test:prepare

它很奇怪,但它有效,也可能对你有所帮助。

【讨论】:

    【解决方案2】:

    这可能是由search_path 问题引起的,如本答案所述:

    https://stackoverflow.com/a/21910573/179316

    【讨论】:

      【解决方案3】:

      将您的 before_script 更改为:

      before_script:
        - psql template1 -c 'create extension hstore;'
        - cp config/database.travis.yml config/database.yml
        - psql -c 'create database virtual_test' -U postgres
      

      请注意,我们在第一行创建了一个扩展。

      【讨论】:

        猜你喜欢
        • 2014-04-02
        • 1970-01-01
        • 2016-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-21
        • 1970-01-01
        • 2013-04-05
        相关资源
        最近更新 更多