【发布时间】:2019-03-13 03:32:59
【问题描述】:
当尝试.update() 或.save() 一行时,我收到此错误:
Unhandled rejection Error: You attempted to save an instance with no primary key,
this is not allowed since it would result in a global update
我尝试了文档用作示例的所有 4 种方法(定义和不定义我要保存的属性),但没有任何效果。 这是我的实际更新代码:
Sydney.databases.guilds.findOrCreate({
attributes: ['guildLocale'],
where: {
guildID: _guild.id,
},
defaults: {
guildID: _guild.id,
guildLocale: 'en_US',
guildPrefix: '?',
},
}).spread((guild, created) => {
guild.update({guildLocale: args[1]})
.then(() => console.log(7))
.catch((e) => throw e);
});
这是公会模式:
let model = sequelize.define('guild', {
guildID: {
field: 'guild_id',
type: DataTypes.STRING,
primaryKey: true,
},
guildLocale: {
field: 'guild_locale',
type: DataTypes.STRING,
},
guildPrefix: {
field: 'guild_prefix',
type: DataTypes.STRING,
},
}, {tableName: 'guilds'});
我在这里错过了什么?
【问题讨论】:
标签: javascript node.js sqlite sequelize.js