How can I check the database field to only accept a row?
In my database, I have two fields:
description: Linecompleted: Boolean
I want the description field to accept only a string value. I mean:
- 'description': 'text' => database accept this request
- 'descrition': true or false => the database denies this request
- 'descrition': 123 => the database denies this request
Currently, the field descriptioncan take a boolean value, so there is a problem in my configuration.
module.exports = function(sequelize, DataTypes) {
return sequelize.define('todo', {
description: {
type: DataTypes.STRING,
allowNull:false,
validate: {
len: [1, 250],
isBoolean:false,
isAlpha:true
}
},
completed: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
validate:{
isBoolean:true
}
}
});
};
source
share