尝试使用ActiveRecord Import更新大型数据集,我正在努力查看为什么我的插入失败。
在我的模型架构中,以下行存在:
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
为什么说此列不存在?索引是否不视为可用于重复键检查的列?我应该如何通过包含两列的索引来检查重复项?
谢谢
答案 0 :(得分:1)
对+ guides(fill = guide_legend(override.aes = list(size = 5, shape = 21)))
使用列名代替索引名
conflict_target