我在项目中一直使用sequelize版本4.44.3。由于使用 separate (link)时遇到问题,我只是尝试升级到v5。安装新版本后,我立即收到此错误:
/node_modules/sequelize/lib/associations/has-many.js:138
this.sourceKeyField = this.source.rawAttributes[this.sourceKey].field || this.sourceKey;
^
TypeError: Cannot read property 'field' of undefined
at HasMany._injectAttributes (/home/nikhil/project/halo/node_modules/sequelize/lib/associations/has-many.js:138:69)
at Function.hasMany (/home/nikhil/project/halo/node_modules/sequelize/lib/associations/mixin.js:37:17)
at Function.BusinessJobPosition.associate (/app/db/models/businessjobposition.js:37:29)
at Object.keys.forEach.modelName (/halo/app/db/models/index.js:32:23)
at Array.forEach (<anonymous>)
at Object.<anonymous> (/app/db/models/index.js:30:17)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
我的模型将如下所示:
module.exports = (sequelize, DataTypes) => {
const label = sequelize.define(
'Label',
{
id: {
type: DataTypes.BIGINT,
allowNull: true,
autoIncrement: true,
primaryKey: true,
},
name: {
type: DataTypes.STRING(200),
allowNull: true,
},
},
{
timestamps: true,
paranoid: true
},
);
label.associate = (models) => {
label.belongsTo(models.Member);
};
return label;
};
我没有找到任何有用的信息here