mysql - SQL error code 1054 unknown column -
this query:
create table if not exists applications ( idresearch int not null, idprof char(10) not null, primary key (idresearch, idprof), foreign key (idresearch) references research(idresearch), foreign key (idprof) references professor(idprof) );
and table:
insert `university`.`applications` (`idresearch`, `idprof`) values ('10', '123456789'); insert `university`.`applications` (`idresearch`, `idprof`) values ('10', '432156789'); insert `university`.`applications` (`idresearch`, `idprof`) values ('10', '789654321'); insert `university`.`applications` (`idresearch`, `idprof`) values ('11', '876098432'); insert `university`.`applications` (`idresearch`, `idprof`) values ('11', '234567890'); insert `university`.`applications` (`idresearch`, `idprof`) values ('12', '432156789'); insert `university`.`applications` (`idresearch`, `idprof`) values ('12', '789654321'); insert `university`.`applications` (`idresearch`, `idprof`) values ('13', '876098432'); insert `university`.`applications` (`idresearch`, `idprof`) values ('14', '876098432'); insert `university`.`applications` (`idresearch`, `idprof`) values ('14', '987654321'); insert `university`.`applications` (`idresearch`, `idprof`) values ('15', '432156789'); insert `university`.`applications` (`idresearch`, `idprof`) values ('16', '123456789'); insert `university`.`applications` (`idresearch`, `idprof`) values ('16', '432156789'); insert `university`.`applications` (`idresearch`, `idprof`) values ('16', '789654321'); insert `university`.`applications` (`idresearch`, `idprof`) values ('17', '789654321'); insert `university`.`applications` (`idresearch`, `idprof`) values ('17', '432156789');
15:26:13 create table if not exists applications ( idresearch int not null, idprof char(10) not null, primary key (idresearch, idprof), foreign key (idresearch) references research(idresearch), foreign key (idprof) references professor(idprof) ) error code: 1215. cannot add foreign key constraint 0.109 sec
there no problem syntax in query, data issue.
before executing insert query, check following
- table 'research' & column 'idresearch' exist
- table 'professor' & column 'idprof' exist
- the reference values (in insert query) columns idresearch, idprof should exist in research , professor tables resp.
truncate\delete , drop 'applications' table manually , create once again. execute insert query.
Comments
Post a Comment