define a sequelize like below: var Program=sequelize.define('Program',{ programCode:{ type:Sequelize.STRING, primaryKey:true }, programName:Sequelize.STRING, }, module.exports.addProgram=function(programData){ return new
Question:
define a sequelize like below:
var Program=sequelize.define('Program',{
programCode:{
type:Sequelize.STRING,
primaryKey:true
},
programName:Sequelize.STRING,
},
module.exports.addProgram=function(programData){
return new Promise((resolve,reject)=>{
for ( var i in programData){
if(programData[i]=="")
programData[i]=null;
};
Program.create({
programCode:programData.programCode,
programName:programData.programName,
}) .then((data) => {
console.log("data:", data)
resolve(data);}
)
.catch((err) => {
reject ("Unable to Add the program");
return;
});
});
}
I know the programCode primaryKey should not be null, but if I input null in programCode, I will get some error. How could I handle this error?