在Sequelize.js中获取验证器错误

时间:2015-03-04 03:46:49

标签: javascript express sequelize.js

我试图验证一个用户名和密码,当发出一个帖子请求时,该用户名和密码不为空,以便没有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
    };
};

1 个答案:

答案 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 herecomment of source code here

在Sequelize 2.0之前,您可以使用notNull验证程序,但它已在2.0版本中删除(请参阅2.0 changes here