0
ich diesen Fehler:Sequelize doppelten Eintrag bekommen: 'ER_DUP_ENTRY'
code: 'ER_DUP_ENTRY',
errno: 1062,
sqlState: '23000',
index: 0,
sql: 'INSERT INTO `users` (`id`,`name`,`environment_hash`) VALUES (DEFAULT,\'dasxdsvfbw\',\'2ec13352-89cc-4921-806f-22c1f3bdf29c\');' },
sql: 'INSERT INTO `users` (`id`,`name`,`environment_hash`) VALUES (DEFAULT,\'dasxdsvfbw\',\'2ec13352-89cc-4921-806f-22c1f3bdf29c\');' }
Wie kann ich dieses Problem beheben?
Dies ist meine Modelle/user.js
"use strict";
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define("User", {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
name: DataTypes.STRING,
environment_hash: {
type: DataTypes.STRING,
defaultValue: DataTypes.UUIDV4
}
}, {
tableName: 'users',
underscored: false,
timestamps: false
}
);
return User;
};
Und das ist mein routes.js:
app.post('/signup', function(request, response){
console.log(request.body.email);
console.log(request.body.password);
User
.find({ where: { name: request.body.email } })
.then(function(err, user) {
if (!user) {
console.log('No user has been found.');
User.create({ name: request.body.email }).then(function(user) {
// you can now access the newly created task via the variable task
console.log('success');
}).catch(function(error) {
console.log(error);
});
}
});
});
Wie erstellen Sie Ihr initiales Datenbankschema? Via Sequelize oder manuell? – drinchev