由于SequelizeUniqueConstraintError,SQLite PUT方法无法正常工作

时间:2019-03-26 19:19:24

标签: javascript sqlite

我构建了一个PUT方法来更新/编辑sqlite db中已插入/现有的记录,并且在触发put方法时,在网络标签中针对PUT请求拉出以下错误消息。该问题似乎与SequelizeUniqueConstraintError有关,并且它在更新时自动创建了一个ID。有什么想法或已知的解决方法吗?:

{
   “ error”:“尝试创建用户时发生错误。”,    “ err”:{
      “ name”:“ SequelizeUniqueConstraintError”,       “错误”:[
         {
            “ message”:“ id必须唯一”,             “ type”:“唯一违规”,             “ path”:“ id”,             “值”:1,             “ origin”:“ DB”,             “实例”:{
               “ id”:1,                “电子邮件”:“ el@gmail.com”,                “密码”:“ $ 2a $ 08 $ HnRjfTzqsvwzobMQYM8bT.IkPbTSe6aOxy50l8 / cUuuVhOgbl513。”,                “ firstName”:“ el”,                “ lastName”:“ leo”,                “ jobDescription”:“测试”,                “收益”:“ 100”,                “费用”:“ 50”,                “余额”:50,                “ isAdmin”:空,                “ youAgree”:为空,                “ createdAt”:“ 2019-03-03T09:39:31.295Z”,                “ updatedAt”:“ 2019-03-26T19:03:21.665Z”             },             “ validatorKey”:“ not_unique”,             “ validatorName”:空,             “ validatorArgs”:[

        ]
     }
  ],
  "fields":[  
     "id"
  ],
  "parent":{  
     "errno":19,
     "code":"SQLITE_CONSTRAINT",
     "sql":"INSERT INTO `Users` (`id`,`email`,`password`,`firstName`,`lastName`,`jobDescription`,`gains`,`costs`,`balance`,`isAdmin`,`youAgree`,`createdAt`,`updatedAt`) VALUES (1,'el@gmail.com','$2a$08$HnRjfTzqsvwzobMQYM8bT.IkPbTSe6aOxy50l8/cUuuVhOgbl513.','el','leo','test','100','50',50,NULL,NULL,'2019-03-03 09:39:31.295 +00:00','2019-03-26 19:03:21.665 +00:00');"
  },
  "original":{  
     "errno":19,
     "code":"SQLITE_CONSTRAINT",
     "sql":"INSERT INTO `Users` (`id`,`email`,`password`,`firstName`,`lastName`,`jobDescription`,`gains`,`costs`,`balance`,`isAdmin`,`youAgree`,`createdAt`,`updatedAt`) VALUES (1,'el@gmail.com','$2a$08$HnRjfTzqsvwzobMQYM8bT.IkPbTSe6aOxy50l8/cUuuVhOgbl513.','el','leo','test','100','50',50,NULL,NULL,'2019-03-03 09:39:31.295 +00:00','2019-03-26 19:03:21.665 +00:00');"
  },
  "sql":"INSERT INTO `Users` (`id`,`email`,`password`,`firstName`,`lastName`,`jobDescription`,`gains`,`costs`,`balance`,`isAdmin`,`youAgree`,`createdAt`,`updatedAt`) VALUES (1,'el@gmail.com','$2a$08$HnRjfTzqsvwzobMQYM8bT.IkPbTSe6aOxy50l8/cUuuVhOgbl513.','el','leo','test','100','50',50,NULL,NULL,'2019-03-03 09:39:31.295 +00:00','2019-03-26 19:03:21.665 +00:00');"

} }

这是供参考的示例PUT方法:

put (user) { console.log('put user: ', JSON.stringify(user)) var userId = user.id console.log('put userId: ', userId) return Api().put(users/${user.id}, user) // return Api().put('users', userId, user) }

0 个答案:

没有答案