MySQL建表错误
我有两个名为
MEMBER 的表 - 列 id(主键)、姓名、电子邮件 和
主题 - 列id、topic_type、created_by。
我想创建一个新表 MEMBER_TO_TOPICS 将成员映射到主题,其中包含列 memberid(成员表 id 的外键)、topicid( 主题表 ID 的外键),created_time。
这是我尝试执行的查询。
CREATE TABLE `gsraisin`.`member_to_topics` (
`member_id` VARCHAR(50) NOT NULL,
`topic_id` VARCHAR(50) NOT NULL,
`created_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`member_id`, `topic_id`),
CONSTRAINT `FK_member_to_topics_memberid` FOREIGN KEY `FK_member_to_topics_memberid`
(`member_id`)
REFERENCES `member` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `FK_member_to_topics_topicid` FOREIGN KEY `FK_member_to_topics_topicid`
(`topic_id`)
REFERENCES `topics` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION
)
ENGINE = InnoDB;
但执行时出现以下错误 - MYSQL 错误号 1005 can't Create table member_to_topics (errno:121)
I have two tables named
MEMBER - columns id(primary key), name, email &
TOPICS - columns id, topic_type, created_by.
I want to create a new table MEMBER_TO_TOPICS which maps member to topics, which has columns memberid(foreign key of member table id), topicid(foreign key of topic table id), created_time.
Here is the query am trying to execute .
CREATE TABLE `gsraisin`.`member_to_topics` (
`member_id` VARCHAR(50) NOT NULL,
`topic_id` VARCHAR(50) NOT NULL,
`created_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`member_id`, `topic_id`),
CONSTRAINT `FK_member_to_topics_memberid` FOREIGN KEY `FK_member_to_topics_memberid`
(`member_id`)
REFERENCES `member` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `FK_member_to_topics_topicid` FOREIGN KEY `FK_member_to_topics_topicid`
(`topic_id`)
REFERENCES `topics` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION
)
ENGINE = InnoDB;
But getting the following error while executing - MYSQL Error Number 1005 can't Create table member_to_topics (errno:121)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在本地机器上尝试过,效果很好。
错误代码 121 表示密钥重复。
我怀疑您可能有重复的约束名称?
I tried this on my local machine and it worked fine.
Error code 121 is for Duplicate Key.
I suspect you may have a duplicated constraint name perhaps?