使用postgres使用hstore的Rails测试数据库出错

Con*_*nor 6 postgresql ruby-on-rails hstore

在Rails 3.2应用程序中使用Postgresql 9.2中的hstore时,我在调试测试数据库时遇到如下错误:

PG ::错误:错误:类型"hstore"不存在

由于它是从schema构建的,因此测试数据库没有经过开发数据库的hstore CREATE EXTENSION迁移.这导致了rake db:test:prepare上的错误.

如何解决这个问题?我实际上发现了一个修复,很高兴听到更多.

Con*_*nor 12

我只是默认启用我的postgresql数据库来支持hstore(通过让模板数据库支持hstore).运行以下命令来执行此操作:

psql -d template0 -c 'create extension hstore;'
Run Code Online (Sandbox Code Playgroud)

然后任何Rails测试数据库将自动支持扩展.

  • 对我来说,`psql -d template1 -c'创建扩展名hstore;'`做了伎俩(Postgres 9.1).根据PostgreSQL.org上的一篇文章,"Template0是'空白'的pgsql数据库模板,它只包含那些开箱即用的东西." (2认同)