Я пытаюсь создать простую регистрационную форму, которую затем перейду к другим операциям CRUD, новым для узла js
Я создал базу данных mysql и выполнил моделирование и связь с Sequelize. Я также создал свой взгляд с помощью pug и сделал console.log для записей из моей формы, и все в порядке, пока он не попадет в базу данных.
var express = require('express');
var router = express.Router();
var Sequelize = require("sequelize");
var db = require('../src/database/connection');
var User = require('../src/model/User');
router.get('/', function(req, res, next){
res.render('signup');
});
router.post('/register', function(req, res, next){
let { username, useremail, pass, re_pass } = req.body;
let errors = [];
//checking feilds
if( !username || !useremail || !pass || !re_pass)
{
errors.push({msg: 'Please no field should be left empty'});
}
//checking Password
if(pass !== re_pass)
{
errors.push({msg: 'Passwords Dont Match'});
}
//check Password Length
if(pass.length < 7)
{
errors.push({msg: 'Passwords should be more than 7 characters '})
}
//reload page with contents if error encountered
if(errors.length > 0)
{
res.render('signup', {
errors,
username,
useremail,
pass,
re_pass
});
} else{
console.log(req.body);
User.create({
username,
useremail,
pass,
}).then(user => res.redirect('/register')).catch(err => console.log(err));
}
});
module.exports = router;
Это ошибка, которую я получаю. ПОЖАЛУЙСТА, ПОМОГИТЕ
{ SequelizeValidationError: notNull Violation: User.email cannot be null,
notNull Violation: User.password cannot be null
at Promise.all.then (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\sequelize\lib\instance-validator.js:74:15)
at tryCatcher (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\promise.js:694:18)
at Promise._fulfill (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\promise.js:638:18)
at PromiseArray._resolve (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\promise_array.js:126:19)
at PromiseArray._promiseFulfilled (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\promise_array.js:144:14)
at Promise._settlePromise (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\promise.js:574:26)
at Promise._settlePromise0 (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\promise.js:694:18)
at _drainQueueStep (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\async.js:138:12)
at _drainQueue (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\async.js:131:9)
at Async._drainQueues (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\ONLINEWIS-PROG-03\Documents\Node\waiyu\node_modules\bluebird\js\release\async.js:17:14)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
name: 'SequelizeValidationError',
errors:
[ ValidationErrorItem {
message: 'User.email cannot be null',
type: 'notNull Violation',
path: 'email',
value: null,
origin: 'CORE',
instance: [User],
validatorKey: 'is_null',
validatorName: null,
validatorArgs: [] },
ValidationErrorItem {
message: 'User.password cannot be null',
type: 'notNull Violation',
path: 'password',
value: null,
origin: 'CORE',
instance: [User],
validatorKey: 'is_null',
validatorName: null,
validatorArgs: [] } ] }