如何访问SequelizeJS(NodeJS)的错误对象

时间:2014-08-17 06:21:51

标签: node.js sequelize.js

我使用' sequelizeJS'编写了以下代码。并希望访问错误对象以提取错误对象包含的验证消息。

var userData = {name: "waqas", email: null};

db.User
  .create(userData)
  .success(function(user) {
    console.log(user);
  })
  .error(function(err){
    console.log(err);  // want to get validation message from 'err' object

  });

console.log(错误)的输出是:

{ [Error: ER_BAD_NULL_ERROR: Column 'email' cannot be null]
  code: 'ER_BAD_NULL_ERROR',
  errno: 1048,
  sqlState: '23000',
  index: 0,
  sql: 'INSERT INTO `users` (`id`,`name`,`email`,`platform`,`email_flag`,`purchased_balance`,`subscription_balance`,`created_at`,`updated_at`) VALUES (DEFAULT,\'waqas\',NULL,\'ios\',true,0,0,\'2014-08-17 06:09:08\',\'2014-08-17 06:09:08\');' }

1 个答案:

答案 0 :(得分:1)

您获得的错误来自数据库,而不是来自sequelize。您需要在电子邮件列中设置allowNull: false以从sequelize

进行验证