[英]ValidationError: “column” is not allowed to be empty on null column
When trying to set passwordResetToken
to null
I get not allowed to be empty errors. 当尝试将passwordResetToken
设置为null
我不允许为空错误。 If I manually run the query against the db, no trouble. 如果我对数据库手动运行查询,就没有麻烦了。
The full code to update user is as follows: 更新用户的完整代码如下:
let user = await this.usersRepository.getById(userId);
// ...
const userData = {
encryptedPassword: await bcrypt.hash(
newPasswd,
Number(process.env.BCRYPT_ROUNDS)
),
passwordResetToken: null,
passwordResetExpires: null
};
user = await this.usersRepository.update(user.id, userData);
I have a model defined as such 我有一个这样定义的模型
const User = sequelize.define(
'user',
{
forename: DataTypes.STRING,
surname: DataTypes.STRING,
email: DataTypes.STRING,
encryptedPassword: DataTypes.STRING,
passwordResetToken: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: null,
validate: {
notEmpty: false
}
},
passwordResetExpires: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: null,
validate: {
isDate: true
}
}
},
{
classMethods: {
associate() {
// associations can be defined here
}
}
}
);
As you can see allowNull
is true, defaultValue
is null and validate: notEmpty
set to false. 如您所见, allowNull
为true, defaultValue
为null并validate: notEmpty
设置为false。 What am I missing? 我想念什么?
Using sequelize v4.42.0 使用sequelize v4.42.0
Dialect 'mysql' 方言'mysql'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.