아래 그림과 같이 양방향 관계로 두 개의 테이블을 만들어야합니다. 하지만 항상 오류가 발생합니다. 나는 테이블을 생성하기 위해 다음 질의를 사용하고있다.MySQL 양방향 관계 및 미러 된 외래 키 관련 문제
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_component에 rpt_operation 없이는 하나의 행을 가질 수 없다)로 정규화 할 수 없다. – Najzero