我是nodejs的新手。我已經使用了nodejs orm的sequelize。但我無法設置驗證屬性;如何在nodejs中使用sequelize設置模型驗證?
型號/ farmer.js
'use strict';
module.exports = function(sequelize, DataTypes) {
var Farmer = sequelize.define('Farmer', {
username:{
type: DataTypes.STRING,
allowNull: false,
},
address: DataTypes.STRING,
email: {
type: DataTypes.STRING,
validate: {
isEmail: true
}
},
phone:{
type: DataTypes.STRING,
allowNull: false,
},
}, {
classMethods: {
associate: function(models) {
Farmer.hasMany(models.Task);
// associations can be defined here
}
}
});
return Farmer;
};
錯誤:
Possibly unhandled SequelizeValidationError: Validation error at /Users/esmrkbr/Desktop/nodejs/sequelize-express-demo/node_modules/sequelize/lib/instance-validator.js:149:14 at tryCatch1 (/Users/esmrkbr/Desktop/nodejs/sequelize-express-demo/node_modules/sequelize/node_modules/sequelize-bluebird/js/main/util.js:43:21) at Promise$_callHandler [as _callHandler] (/Users/esmrkbr/Desktop/nodejs/sequelize-express-demo/node_modules/sequelize/node_modules/sequelize-bluebird/js/main/promise.js:639:13) at Promise$_settlePromiseFromHandler [as _settlePromiseFromHandler] (/Users/esmrkbr/Desktop/nodejs/sequelize-express-demo/node_modules/sequelize/node_modules/sequelize-bluebird/js/main/promise.js:653:18) at Promise$_settlePromiseAt [as _settlePromiseAt] (/Users/esmrkbr/Desktop/nodejs/sequelize-express-demo/node_modules/sequelize/node_modules/sequelize-bluebird/js/main/promise.js:817:14) at Promise$_settlePromises [as _settlePromises] (/Users/esmrkbr/Desktop/nodejs/sequelize-express-demo/node_modules/sequelize/node_modules/sequelize-bluebird/js/main/promise.js:951:14) at Async$_consumeFunctionBuffer [as _consumeFunctionBuffer] (/Users/esmrkbr/Desktop/nodejs/sequelize-express-demo/node_modules/sequelize/node_modules/sequelize-bluebird/js/main/async.js:75:12) at Async$consumeFunctionBuffer (/Users/esmrkbr/Desktop/nodejs/sequelize-express-demo/node_modules/sequelize/node_modules/sequelize-bluebird/js/main/async.js:38:14) at doNTCallback0 (node.js:419:9) at process._tickCallback (node.js:348:13)
如何設置驗證模式?