未处理拒绝TypeError:undefined不是函数
错误我想在MySQL上面的sequelize中更新我的表。
这里是一段代码片段,可以通过令人惊讶的评论来触发错误:
topic.update(
{ name: "adfa"},
{ where: { tid: 1} }
);
//topicAttribute.update({ value: "name 2"},{where: {TOPIC: 2,name: "nadpis" }});
现在这是我的两个模特:
var topic = sequelize.define('topic', {
tid: { type: Sequelize.INTEGER,
field: 'tid',
primaryKey: true
},
name: { type: Sequelize.STRING,
field: 'name'
},
added: { type: Sequelize.DATE,
field: 'added'
},
addedBy: { type: Sequelize.STRING,
field: 'added_by'
},
changed: { type: Sequelize.DATE,
field: 'changed'
},
changedBy: { type: Sequelize.STRING,
field: 'changed_by'
},
parent: { type: Sequelize.INTEGER,
field: 'parent'
},
enabled: {
type: Sequelize.BOOLEAN,
field: 'enabled'
}
},
{
tableName: 'topic',
timestamps: false
});
var topicAttribute = sequelize.define('tAttribute', {
parent: { type: Sequelize.INTEGER,
field: 'TOPIC',
primaryKey: true
},
name: { type: Sequelize.STRING,
field: 'name',
primaryKey: true
},
value: { type: Sequelize.STRING,
field: 'value'
},
},
{
tableName: 'topic_attribute',
timestamps: false
});
topic.hasOne(topic, {foreignKey: 'tid'});
topic.hasMany(topicAttribute, {foreignKey: 'parent'});
topicAttribute.belongsTo(topic, {foreignKey: 'parent'});
最后我的堆栈跟踪:
Unhandled rejection TypeError: undefined is not a function
at Instance.set (C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\instance.js:365:16)
at Instance.set (C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\instance.js:293:16)
at initValues (C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\instance.js:63:8)
at Instance (C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\instance.js:107:14)
at new Instance (C:\Users\212443162\Documents\ithd\node_modules\sequelize\li b\model.js:655:14)
at Model.build (C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\model.js:1493:10)
at C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\model.js:2119:24
at tryCatcher (C:\Users\212443162\Documents\ithd\node_modules\sequelize\node_modules\bluebird\js\main\util.js:24:31)
at Function.Promise.attempt.Promise.try (C:\Users\212443162\Documents\ithd\node_modules\sequelize\node_modules\bluebird\js\main\method.js:31:24)
at Model.update (C:\Users\212443162\Documents\ithd\node_modules\sequelize\li b\model.js:2116:21)
at C:\Users\212443162\Documents\ithd\routes\topics.js:119:8 at Layer.handle [as handle_request] (C:\Users\212443162\Documents\ithd\node_ modules\express\lib\router\layer.js:95:5)
at next (C:\Users\212443162\Documents\ithd\node_modules\express\lib\router\r oute.js:131:13)
at Route.dispatch (C:\Users\212443162\Documents\ithd\node_modules\express\li b\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\212443162\Documents\ithd\node_ modules\express\lib\router\layer.js:95:5)
at C:\Users\212443162\Documents\ithd\node_modules\express\lib\router\index.j s:277:22