【发布时间】:2019-11-25 06:02:32
【问题描述】:
尝试使用 ActiveRecord 导入更新大型数据集时,我很难理解插入失败的原因。
在我的模型架构中,存在这一行:
t.index ["variant_id", "stock_location_id"], name: "index_spree_stock_items_on_variant_id_and_stock_location_id", unique: true, where: "(deleted_at IS NULL)"
对于导入,我正在尝试更新其中的许多,当我运行时:
Spree::StockItem.import columns, values, :on_duplicate_key_update => [:count_on_hand]
我收到:
duplicate key value violates unique constraint "index_spree_stock_items_on_variant_id_and_stock_location_id"
但是当我跑步时:
Spree::StockItem.import columns, values, :on_duplicate_key_update =>{ conflict_target: [:index_spree_stock_items_on_variant_id_and_stock_location_id], columns: [:count_on_hand] }
我收到:
column "index_spree_stock_items_on_variant_id_and_stock_location_id" does not exist
为什么说这个栏目不存在?索引是否不被视为可用于重复键检查的列?我应该如何通过由两列组合而成的索引来检查重复项?
谢谢
【问题讨论】:
标签: ruby-on-rails postgresql spree solidus activerecord-import