Mysql 为什么Id只保存在数据库中而没有其他数据?

Mysql 为什么Id只保存在数据库中而没有其他数据?,mysql,reactjs,sequelize.js,passport.js,Mysql,Reactjs,Sequelize.js,Passport.js,我正在使用Passport、sequelize和MySql向React应用程序添加身份验证,但数据并没有保存到MySql数据库中,只有Id和null字段。 我正在努力实施当地的战略 在《邮递员》中尝试发帖路线时,我得到了200条回复、电子邮件和哈希密码。但是,ID字段显示为空。在检查mysql数据库时,我可以看到添加了ID的新行,但用户名和密码为空。这里有我遗漏的东西吗 护照策略文件 const Strategy = require('passport-local').Strategy; con

我正在使用Passport、sequelize和MySql向React应用程序添加身份验证,但数据并没有保存到MySql数据库中,只有Id和null字段。 我正在努力实施当地的战略

在《邮递员》中尝试发帖路线时,我得到了200条回复、电子邮件和哈希密码。但是,ID字段显示为空。在检查mysql数据库时,我可以看到添加了ID的新行,但用户名和密码为空。这里有我遗漏的东西吗

护照策略文件

const Strategy = require('passport-local').Strategy;
const User = require('../models').User;
const bcrypt = require('bcryptjs');
const salt = bcrypt.genSaltSync(10);

const SignupStrategy = new Strategy({ passReqToCallback: true, 
usernameField: "email", passwordField: "password" }, function (req, email, 
password, done) {

User.findOne({
    where: {
        email: email
    }
})
    .then((user, error) => {
        if (error)
        return done(null, user);
    })
const encryptedPassword = bcrypt.hashSync(password, salt);
let newUser = new User({
    email,
    password: encryptedPassword
})
User.create(newUser)
    .then((user) => {
        newUser
        ;
        done(null, newUser)
    })
    .catch((error) => {
        done(error, null)
    })    
});

module.exports = SignupStrategy;
用户模型

 module.exports = function (sequelize, DataTypes) {
 var User = sequelize.define("User", {
 username: {
  type: DataTypes.STRING,
  // allowNull: false,
  unique: true,
  validate: {
    len: [1]
  }
 },
 email: {
    type: DataTypes.STRING,
  // allowNull: false,
    unique: true,
    validate: {
    isEmail: true
    }
  },
 password: {
  type: DataTypes.STRING,
  // allowNull: false
  }
  });

  return User;
 };
路线

护照索引文件

const passport = require('passport');

const SignupStrategy = require('./SignupStrategy');
const SigninStrategy = require('./SigninStrategy');

passport.use('local-signin', SigninStrategy);
passport.use('local-signup', SignupStrategy);

module.exports = passport;

如果我在用户模型中将allowNull设置为true,那么我将从sequelize获得验证错误(非空冲突)。不确定现在要做什么,请改为:

let newUser = new User({
    email,
    password: encryptedPassword
})
let newUser = {
    email,
    password: encryptedPassword
};
使用以下命令:

let newUser = new User({
    email,
    password: encryptedPassword
})
let newUser = {
    email,
    password: encryptedPassword
};
不需要创建任何特殊对象来创建条目,它将 只需要简单的json对象


@AlexYepes,请接受答案并投票,如果它解决了你的问题。对不起,由于我的乞丐级别,我只能接受答案,但还不能投票。我只能说:非常感谢:)@AlexYepes,现在试试,你可以:)@AlexYepes,快乐编码:D