0
最近我在Sequelize中做了bulkCreate時遇到了一些麻煩。我得到了以下錯誤:sequelize BulkCreate無法讀取未定義的屬性'set'
TypeError: Cannot read property 'set' of undefined
at results.forEach (/Users/mzd/Desktop/Shroogal/shroogal-dev/node_modules/sequelize/lib/model.js:2357:27)
at Array.forEach (<anonymous>)
at QueryInterface.bulkInsert.then.results (/Users/mzd/Desktop/Shroogal/shroogal-dev/node_modules/sequelize/lib/model.js:2356:21)
at tryCatcher (/Users/mzd/Desktop/Shroogal/shroogal-dev/node_modules/sequelize/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/mzd/Desktop/Shroogal/shroogal-dev/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/Users/mzd/Desktop/Shroogal/shroogal-dev/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/Users/mzd/Desktop/Shroogal/shroogal-dev/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/Users/mzd/Desktop/Shroogal/shroogal-dev/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/Users/mzd/Desktop/Shroogal/shroogal-dev/node_modules/sequelize/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/Users/mzd/Desktop/Shroogal/shroogal-dev/node_modules/sequelize/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/Users/mzd/Desktop/Shroogal/shroogal-dev/node_modules/sequelize/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:781:20)
at tryOnImmediate (timers.js:743:5)
at processImmediate [as _immediateCallback] (timers.js:714:5)
這是我sequelize遷移文件:
module.exports = function(sequelize, DataTypes) {
return sequelize.define('documentsInstruments', {
docid: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true,
field: 'docid'
},
iid: {
type: DataTypes.BIGINT,
allowNull: true,
references: {
model: 'EntityInstruments',
key: 'IID'
},
field: 'IID'
},
docType: {
type: DataTypes.STRING(45),
allowNull: true,
field: 'docType'
},
docPath: {
type: DataTypes.STRING(200),
allowNull: true,
field: 'docPath'
},
creationDate: {
type: DataTypes.DATE,
allowNull: true,
field: 'creationDate'
},
addlInfo: {
type: DataTypes.STRING(500),
allowNull: true,
field: 'addlInfo'
},
posLabel: {
type: DataTypes.STRING(45),
allowNull: true,
field: 'posLabel'
},
active: {
type: DataTypes.STRING(3),
allowNull: true,
defaultValue: 'Y',
field: 'active'
},
origFileName: {
type: DataTypes.STRING(400),
allowNull: true,
field: 'origFileName'
}
}, {
tableName: 'Documents_Instruments'
});
};
這是我bulkCreate功能:
if(obj.documents) {
let data = [];
obj.documents.forEach((v, i) => {
var d = {};
if(v.docid)
d.docid = v.docid;
if(obj.iid)
d.iid = obj.iid;
if(v.type)
d.docType = v.type;
if(v.filePath)
d.docPath = v.filePath;
if(v.date)
d.creationDate = v.date;
if(v.additionalDescription)
d.addlInfo = v.additionalDescription;
if(v.originalName)
d.origFileName = v.originalName;
data.push(d);
});
this.documentsInstruments
.bulkCreate(data, {
updateOnDuplicate: ['docType', 'docPath', 'creationDate', 'addlInfo', 'origFileName']
})
.then((d) => {
resolve(d);
})
.catch((err) => {
reject(err);
});
}
我檢查源代碼(node_modules/sequelize/lib/model.js:2357:27)並嘗試打印某些內容以進行調試,實例[i]在此取消定義.QueryInterface.bulkInsert函數
是的,我還沒有看到這個錯誤了。 Sequelize可能已經修復了它。不管怎麼說,還是要謝謝你 –