删除重复键的MySQL复制键

时间:2018-06-28 10:54:13

标签: mysql primary-key on-duplicate-key

我们有一个具有以下结构的表格,

CREATE TABLE `DateTracker` (
  `ReferenceType` varchar(50) NOT NULL,
  `Date` date NOT NULL,
  `LastRunDate` datetime DEFAULT NULL,
  PRIMARY KEY (`ReferenceType`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

此表将根据其他表上生成的数据和数据可用性的最后日期进行更新。

例如,如果我们有一个名为“用户”的表,

CREATE TABLE `User` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Username` varchar(50) NOT NULL,
  `Date` date NOT NULL
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `user` (`Id`,`Username`,`Date`) VALUES (1,'user1','2018-06-22');
INSERT INTO `user` (`Id`,`Username`,`Date`) VALUES (2,'user2','2018-06-24');

然后,作为最后处理的条目的日期为'2018-06-24',我们将在DateTracker表中有一条记录,

INSERT INTO `DateTracker` (`ReferenceType`,`Date`,`LastRunDate`) VALUES ('User','2018-06-24','2018-06-28 12:56:37');

现在,当我们手动删除DateTracker表中的条目时,生成此数据的脚本将创建一个新条目,并将在脚本的进一步运行时对其进行更新。

问题是,有时我们在删除后插入"1062: Duplicate entry 'User' for key 'PRIMARY'"时会显示ReferenceType,但是'User'// create an object in the addon var OB = require('./build/Debug/objectwraphandle.node') var obj = new OB.MyObject(42) // just an async wait function async function asyncFunc1(y) { return new Promise((resolve, reject) => { setTimeout(() => resolve('asyncFunc1: DONE'), 2000); }); } // pass the async function as callback to the addon and call it obj.callAsyncFunction(asyncFunc1); // ask the object, it the promise is already resolved. // this should switch from 1 (Pending) to 0 (Resolved) after 2 seconds console.log(" resolved? : " + obj.isPromiseResolved()); // but this core-dumps with: // "FATAL ERROR: v8::Promise::Cast Could not convert to promise" 中实际上没有行。

我很困惑为什么会收到此错误。任何帮助,将不胜感激。

0 个答案:

没有答案