我有一个迁移,我在其中创建了一个像这样的产品表
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name
t.hstore :data
t.timestamps
end
end
end
关于 activerecord-postgres-hstore page他们使用
在表中添加索引(在 SQL 中)CREATE INDEX products_gin_data ON products USING GIN(data);
但是迁移不会跟踪该更改(我猜是因为它是 Postgres 特定的?),有没有办法从迁移中创建索引?
谢谢!
最佳答案
在 Rails 4 中,您现在可以在迁移中执行类似的操作:
add_index :products, :data, using: :gin
关于ruby-on-rails - Rails 和 Postgres Hstore : Can you add an index in a migration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10592221/