【发布时间】:2012-09-12 11:12:21
【问题描述】:
我必须创建两个具有双向关系的表,如下图所示。 但它总是给出一个错误。我正在使用以下查询来创建表。
CREATE TABLE IF NOT EXISTS `rpt_operation` (
`op_id` int(45) NOT NULL,
`component` int(45) NOT NULL,
`ideal_time` time NOT NULL,
`handling_time` time NOT NULL,
PRIMARY KEY (`op_id`),
INDEX (component),
FOREIGN KEY (component)
REFERENCES rpt_component(comp_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `rpt_component` (
`comp_id` int(45) NOT NULL,
`lot_code` int(60) NOT NULL,
`lot_color` varchar(60) NOT NULL,
`drawing_num` int(60) NOT NULL,
`revision_num` int(60) NOT NULL,
`operation` int(45) NOT NULL,
PRIMARY KEY (`comp_id`),
INDEX (operation),
FOREIGN KEY (operation)
REFERENCES rpt_operation(op_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
错误出现在rpt_operation 表的component int(45) NOT NULL 行。
任何帮助将不胜感激。
提前致谢
【问题讨论】:
-
首先,这很可能是由于命令的顺序,您可以先创建两个表,然后在它们上设置索引。无论如何,“双向”关系有时是一个更好的提示,但两个表都放入一个更大的表中(在 rpt_operation 中不能有一行,而 rpt_component 中没有一行),因为这样做我看不到规范化的中断。
标签: mysql replication bidirectional