sequelize继续覆盖mysql中的行

时间:2017-04-06 17:51:10

标签: javascript mysql node.js express sequelize.js

我正在尝试使用sequelize在节点中创建用户数据库,每次我尝试将新用户添加到我的数据库时,它只是替换当前用户而不是添加其他用户。我添加的人将获得ID 1,该人将成为表中唯一的人。我还没有创建我的控制器所以我在我的服务器js中创建了。我不确定问题是在模型中还是在服务器js中。想法?

用户模型:

module.exports = function(sequelize, DataTypes) {
var Auth_user = sequelize.define('Auth_user', {
    id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true
    },
    password: {
        type: Sequelize.CHAR(128),
        allowNull: false
    },
    first_name: {
        type: Sequelize.CHAR(30),
        allowNull: false
    },
    last_name: {
        type: Sequelize.CHAR(30),
        allowNull: false
    },
    is_superuser: {
        type: Sequelize.INTEGER(1),
        allowNull: false`enter code here`
    },
    last_login: DataTypes.DATE,
    email: {
        type: Sequelize.STRING,
        allowNull: false,
        unique: true
    },
    gender: {
        type: Sequelize.STRING(1)
    },
    role: {
        type: Sequelize.CHAR(3),
        allowNull: false
    },
    is_active: {
        type: Sequelize.INTEGER(1),
        allowNull: false
    },
    createdAt: DataTypes.DATE,
    updatedAt: DataTypes.DATE,
    livox_customer_id: {
        type: Sequelize.INTEGER,
        allowNull: false
    },
    language_id: DataTypes.STRING
}, {
    classMethods: {
        associate: function(models) {
            Auth_user.hasOne(models.Livox_holder)
        }
    }
});
return Auth_user;};

server.js文件

    var models = require('./api/models')


var sequelizeConnection = models.sequelize;



sequelizeConnection.query('SET FOREIGN_KEY_CHECKS = 0')



.then(function(){
    return sequelizeConnection.sync({force:true})
}) 

.then(function(){

return models.Auth_user.create(
    {

        password: "password2",
        first_name: "John",
        last_name: "Doe",
        is_superuser: 1,
        email: "johndoe@aol.com",
        role: "thr",
        is_active: 1,
        livox_customer_id: 00345654322, 

        Livox_holder:{
            professional_record: "I am a doctor with a phd in early childhood development",
            zipcode: 21345,
            address: "101 hostiptal drive",
            city: "Orlando",
            state: "FL",
            phone_number: 407123456,
            disclosure_auth: 1234,
            sms: 1,
            pin_number: 654321,
            livox_licenses_id: 223456789
        }, 
    }, 


    {

        include: [models.Livox_holder]
    }
)

})

0 个答案:

没有答案