2016-11-20 5 views
0

私はこのエラーを取得しています:Sequelizeは、重複したエントリを取得: '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\');' } 

がどのように私はこの問題を解決することができましたか?

これは

"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; 
}; 

私のモデル/ user.jsのであり、これは私のroutes.jsです:Sequelize thenコールバックの

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); 
         }); 

       } 
      }); 



    }); 
+0

初期データベーススキーマはどのように作成しますか?続行するか、手動でか? – drinchev

答えて

0

最初のパラメータは、クエリの結果、エラーではありません。すべてのエラーはcatchコールバックによって処理されます。 Sequelizeクエリの構文:

Model.find().then(function(result){ 
    //handling result 
}).catch(function(error){ 
    //handling error 
}); 
関連する問題