未知键::表达式。有效键是::unique, :order, :name, :where, :length, :internal, :using, :algorithm, :type

Unknown key: :expression. Valid keys are: :unique, :order, :name, :where, :length, :internal, :using, :algorithm, :type

我正在尝试为 jsonb 列组的 table 用户创建一个 gin 索引。在哈希键 group_id 上。我正在使用 rails 5.0.2。 Postgres 9.6。请帮忙

add_index :users, :groups, :using => :gin, :expression => "(groups->>'group_id')", :name => 'group_id_index'

我的想法来自

引用您链接到的问答中的评论:

add_index :table_name, "(field->'array_key')", using: :gin, name: 'index_table_name_on_field_array_keys' in Rails 5.0.0

您的 rails 版本似乎没有使用正确的语法。