问题描述:
有如下三个表
表关系描述:
1.category表存放有目录id以及名字。
2.category_product表存放有category_id对应category表的id,product_id对应相应的product表,里面有产品的详细信息。
目前建模关系:
category模型中
category.hasMany(category_product,{foreignKey:'id',targetKey:'category_id'})
category_product模型中
category_product.belongsTo(Product, {foreignKey: 'product_id',targetKey: 'id'})
报错问题:
SequelizeDatabaseError: Unknown column 'category_product.id' in 'field list'
此外
hasMany
已经废除targetKey
了,如果你要用非id
做关联键用sourceKey
,但从你数据结构来看并不需要。