我试图向数据库添加索引,但我不断收到错误消息:
PG::SyntaxError: ERROR: DEFAULT is not allowed in this context
在阅读了几个小时的文档后,我似乎无法解决这个问题。
我正在运行这个:
"CREATE UNIQUE INDEX index_uniq_service_models_default ON service_models(zone_id) WHERE default"
我的表如下所示:
create_table :service_models do |t|
t.string :name, null: false
t.jsonb :configuration, null: false, default: "{}"
t.boolean :default, null: false
t.json :metadata, null: false, default: "{}"
t.references :zone, foreign_key: true, null: false, index: { name: idx_name(:service_models, :zones) }
t.timestamps
end
我想要做的是一个 ServiceModel 只有一个区域的默认值。
一个区域可以有许多 ServiceModel,但它只能有 1 个默认的。