What happens is that I have a primary key composed in a table and that key must be foreign in another table. Could someone help me please?
Example:
CREATE TABLE 'detallehorario' (
'Id_Grupo' int(11) NOT NULL,
'Dia' varchar(15) COLLATE latin1_bin NOT NULL,
'HoraEntrada' time NOT NULL,
'HoraSalida' time NOT NULL,
PRIMARY KEY ('Id_Grupo','Dia'),
KEY 'Id_Grupo_idx' ('Id_Grupo'),
CONSTRAINT 'Id_Grupo' FOREIGN KEY ('Id_Grupo') REFERENCES 'grupo' ('Id_Grupo') ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
This key is composed of two fields, worth the redundancy and I need to have it as foreign in the Student table; The code that I try to implement is the following:
CREATE TABLE 'alumno' (
'Matricula' varchar(15) COLLATE latin1_bin NOT NULL,
'Nombre' varchar(50) COLLATE latin1_bin NOT NULL,
'ApellidoPaterno' varchar(50) COLLATE latin1_bin NOT NULL,
'ApellidoMaterno' varchar(50) COLLATE latin1_bin NOT NULL,
'Id_Grupo' varchar(45) COLLATE latin1_bin NOT NULL,
'Dia' varchar(15) COLLATE latin1_bin NOT NULL,
PRIMARY KEY ('Matricula'),
CONSTRAINT 'Id_Grupo' FOREIGN KEY ('Id_Grupo','Dia') REFERENCES 'detallegrupo' ('Id_Grupo','Dia') ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
Will anyone have an idea of why I get the error? Thank you in advance