我似乎无法使用以下MySQL-Query:
CREATE TABLE task_one_line (
`timestampStart` BIGINT NOT NULL,
`userId` VARCHAR(64) NOT NULL,
PRIMARY KEY (`timestampStart`, `userId`)
)ENGINE=InnoDB
CREATE TABLE task_one_included_object (
`objectId` INTEGER NOT NULL,
`timestampStart` BIGINT NOT NULL,
`userId` VARCHAR(64) NOT NULL,
PRIMARY KEY (`objectId`, `userId`, `timestampStart`),
FOREIGN KEY(`userId`, `timestampStart`) REFERENCES task_one_line (`userId`, `timestampStart`)
)ENGINE=InnoDB
它给出了:
ERROR 1005 (HY000): Can't create table 'crowdtracker.task_one_included_object' (errno: 150)
根据MySQL-Manual指出外键约束的错误。但是所有外键都具有与引用属性相同的约束,因此我无法理解错误。我错过了什么?
祝你好运
答案 0 :(得分:0)
订单会对主键的引用产生影响。您的引用为timestampStart, userId
。它应该是另一种顺序:
CREATE TABLE task_one_line (
`timestampStart` BIGINT NOT NULL,
`userId` VARCHAR(64) NOT NULL,
PRIMARY KEY (userId, `timestampStart`)
);
CREATE TABLE task_one_included_object (
`objectId` INTEGER NOT NULL,
`timestampStart` BIGINT NOT NULL,
`userId` VARCHAR(64) NOT NULL,
PRIMARY KEY (`objectId`, `userId`, `timestampStart`),
FOREIGN KEY(`userId`, `timestampStart`) REFERENCES task_one_line (`userId`, `timestampStart`)
);