当我尝试像这样更新令牌[0]的accessstoken时,
tokens[0].accesstoken = newTokenObj.accesstoken;
tokens[0].save();
我明白了:
Unhandled rejection SequelizeValidationError: string violation: updatedAt cannot be an array or an object
我只更改了accessstoken,并且Sequelize应该更新updatedAt时间戳。为什么会发生这个错误?
这是令牌[0],令牌中唯一的元素
accesstoken {
dataValues:
{ id: 1,
accesstoken: '10_PRQpRztWb1ZL3hgLwLhaftmputRbePB39VxIJ-sCdFfzIPGjWEOX_DYV_Y18MOHHpuRmWDrTBVK7twkas_-KknBjo4vo1fiy-mlUIt_dgLMGkqjPFYCXNhuxZwBanbu27kan9IFfvkOOS1zABPKdADAJXS',
updatedAt: 2018-05-21T01:12:25.000Z,
createdAt: 2018-05-21T15:12:08.000Z },
_previousDataValues:
{ id: 1,
accesstoken: '10_ZMeWuvau9H3ATIGC3g_xoWRHOOpkHietdHommGIQ4Ms5Wo_jZQVy_mv0fG6hbA8QBeSWlBHnlP6bWEnwy_rpCAajYhlGtlZLcgGLMvv1ZRBOCW4JGddmPv19quwKoSYazmX0wUEteuQei0lvXUEfABATQA',
updatedAt: 2018-05-21T01:12:25.000Z,
createdAt: 2018-05-21T15:12:08.000Z },
_changed: { accesstoken: true },
_modelOptions:
{ timestamps: true,
validate: {},
freezeTableName: false,
underscored: false,
underscoredAll: false,
paranoid: false,
rejectOnEmpty: false,
whereCollection: { id: 1 },
schema: null,
schemaDelimiter: '',
defaultScope: {},
scopes: [],
indexes: [],
name: { plural: 'accesstokens', singular: 'accesstoken' },
omitNull: false,
sequelize:
Sequelize {
options: [Object],
config: [Object],
dialect: [Object],
queryInterface: [Object],
models: [Object],
modelManager: [Object],
connectionManager: [Object],
importCache: {},
test: [Object] },
hooks: {},
uniqueKeys: {} },
_options:
{ isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [ 'id', 'accesstoken', 'updatedAt', 'createdAt' ] },
__eagerlyLoadedAssociations: [],
isNewRecord: false }
当我使用更新时,我得到了同样的错误
tokens[0].update({
accesstoken:newTokenObj.accesstoken
});
所以我只能设置validate:false来传递验证步骤