I have written following piece of code using 'sequelizeJS' and want to access error object to extract the validation message contained by the err object.
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
});
The output of console.log(err) is:
{ [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\');' }
The error you are getting is from the database, not from sequelize. You will need to set allowNull: false
on your email column to get validation from sequelize