如何在下表的gpa列中指定0.0到4.0之间的范围?
const Student = db.define('student', {
firstname: {
type: Sequelize.STRING,
validate: {
notEmpty: true,
},
allowNull: false,
},
lastname: {
type: Sequelize.STRING,
validate: {
notEmpty: true,
},
allowNull: false,
},
gpa: {
type: Sequelize.INTEGER,
}
});
答案 0 :(得分:0)
我认为这可以帮助您验证:
const Student = db.define('student', {
...
gpa: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
validate: {
min: 0,
max: 4
}
}
...
})
更多详细信息: DO READ