我定义了以下模型:
module.exports = function(sequelize, DataTypes) {
// Brand
var Brand = sequelize.define("Brand", {
name: DataTypes.STRING
},{tableName: "brand"});
// Product_Type
var Product_Type = sequelize.define("Product_Type", {
name: DataTypes.STRING
},{tableName: "product_type"});
// Product
var Product = sequelize.define("Product", {
name: DataTypes.STRING,
product_type_id: {
type: DataTypes.INTEGER,
references: Product_Type,
referencesKey: "id"
},
brand_id: {
type: DataTypes.INTEGER,
references: Brand,
referencesKey: "id"
},
weight: DataTypes.INTEGER
},{tableName: "product"});
Brand.hasMany(Product);
Product_Type.hasMany(Product);
Product.belongsTo(Brand);
Product.belongsTo(Product_Type);
return Product;
};
我收到此错误:
Possibly unhandled SequelizeDatabaseError: ER_BAD_FIELD_ERROR: Unknown column 'BrandId' in 'field list'
如何判断sequelize使用正确的字段?使用BrandId
代替brand_id
而不是ProductTypeId
来使用product_type_id
。
我认为引用它就足够了,还是我通过关联再次指定它?