我试图验证一个用户名和密码,当发出一个帖子请求时,该用户名和密码不为空,以便没有empy行,但我一直在
Express server listening on port 5000
/Users/ra/Desktop/Jos/node_modules/sequelize/lib/dao-validator.js:216
throw new Error("Invalid validator function: " + validatorType)
^
Error: Invalid validator function: allowNull
继承人的雇主模式
'use strict';
var Sequelize = require('sequelize');
module.exports = function (sequelize) {
var Employer = sequelize.define("employer", {
username: { type: Sequelize.STRING, validate: { allowNull: false } },
password: { type: Sequelize.STRING, validate: { allowNull: false } }
});
return {
Employer: Employer
};
};
答案 0 :(得分:6)
allowNull
必须在字段选项中,而不是在验证程序中:
var Sequelize = require(' sequelize');
'use strict';
var Sequelize = require('sequelize');
module.exports = function (sequelize) {
var Employer = sequelize.define("employer", {
username: { type: Sequelize.STRING, allowNull: false },
password: { type: Sequelize.STRING, allowNull: false }
});
return {
Employer: Employer
};
};
请参阅doc here和comment of source code here
在Sequelize 2.0之前,您可以使用notNull
验证程序,但它已在2.0版本中删除(请参阅2.0 changes here)