CREATE TABLE
다음은 작동하지 않습니다FK는 충돌을 야기
CREATE TABLE IF NOT EXISTS `transacciones`.`jos_trans_sector` (
`id_sector` INT NOT NULL,
`nombre` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`id_sector`),
CONSTRAINT `fk_sector_empresa_sector1`
FOREIGN KEY (`id_sector`)
REFERENCES `transacciones`.`jos_trans_empresa_sector` (`id_sector`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
내가 얻을 : Error Code: 1005. Can't create table 'transacciones.jos_trans_sector' (errno: 150)
내가 SHOW ENGINE INNODB STATUS;
을 사용하면 내가 다음과 같은 출력 얻을 :
------------------------
LATEST FOREIGN KEY ERROR
------------------------
170509 16:14:06 Error in foreign key constraint of table transacciones/jos_trans_sector:
FOREIGN KEY (`id_sector`)
REFERENCES `transacciones`.`jos_trans_empresa_sector` (`id_sector`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB:
Cannot find an index in the referenced table where the [...]
을
id
과 01 사이에 다른 유형에 대해 이야기하는 게시물을 확인했습니다.이지만 두 가지 모두 동일했습니다 (INT
)
아이디어가 있으십니까?
미리 감사드립니다.
FK가 참조 할 수 있도록 jos_trans_empresa_sector에 기본 키가 있습니까? –
"크래시"가 없으며 오류가 아주 분명합니다. 참조하는 테이블의 적절한 컬럼을'unique' 또는'primary key'로 선언하십시오. –
감사합니다. 나는'N-M' 관계를 만들 때'인덱스 '를 만들어야한다는 것을 몰랐습니다. –