2009-09-27 7 views
0

J'ai ce schéma:pourquoi ne peut pas ajouter cette clé étrangère?

CREATE TABLE `lotto`.`combinaciones` (
    `indice` mediumint(8) unsigned NOT NULL, 
    `binario` int(10) unsigned NOT NULL, 
    PRIMARY KEY USING BTREE (`indice`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 

CREATE TABLE `lotto`.`sorteo` (
    `numeroSorteo` int(11) NOT NULL, 
    `fechaSorteo` date NOT NULL, 
    `precioCarton` double NOT NULL, 
    `valorSerial` double NOT NULL, 
    `valorMiniserial` double NOT NULL, 
    `estatusSorteo` int(11) NOT NULL, 
    `cantidadCartones` int(11) NOT NULL, 
    PRIMARY KEY (`numeroSorteo`), 
    UNIQUE KEY `fechaSorteo` (`fechaSorteo`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 

CREATE TABLE `lotto`.`cartones` (
    `numeroSorteo` int(11) NOT NULL, 
    `serial` mediumint(9) NOT NULL, 
    `indice` mediumint(8) NOT NULL, 
    `binario` int(11) NOT NULL, 
    `miniserial` smallint(6) NOT NULL, 
    `estatus` tinyint(4) NOT NULL default '0', 
    PRIMARY KEY (`numeroSorteo`,`serial`), 
    KEY `new_index` (`indice`), -- ADD LATER 
    CONSTRAINT `cartones_ibfk_1` FOREIGN KEY (`numeroSorteo`) REFERENCES `sorteo` (`numeroSorteo`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 

Je suis en train d'ajouter ceci:

ALTER TABLE `lotto`.`cartones` ADD CONSTRAINT `new_fk_56` FOREIGN KEY `new_fk_56` (`indice`) 
    REFERENCES `combinaciones` (`indice`) 
    ON DELETE RESTRICT 
    ON UPDATE RESTRICT; 

MAIS INNODB arrête tout se plaindre de ne pas trouver un indice:

Cannot find an index in the referenced table where the referenced columns appear as the first columns...

Mais il est pas la clé étrangère: combinaciones(indice) le même que la clé étrangère sorteo(numeroSorteo)?, qui est worki ng

EDIT:

Je l'ai testé avec: KEY 'new_index' () à lotto.cartones indice et sans elle.

+0

Est-ce la dernière erreur de clé étrangère de 'SHOW ENGINE INNODB STATUS'? – derobert

Répondre

5
`indice` mediumint(8) NOT NULL, 

n'est pas le même type que

`indice` mediumint(8) unsigned NOT NULL, 

Vous devez faire vos deux indice non signé ou non signé aucun d'entre eux.

+0

Merci qui a résolu mon problème! – Cesar

Questions connexes