这是我的查询:

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)
);

这是表:
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('10', '123456789');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('10', '432156789');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('10', '789654321');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('11', '876098432');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('11', '234567890');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('12', '432156789');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('12', '789654321');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('13', '876098432');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('14', '876098432');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('14', '987654321');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('15', '432156789');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('16', '123456789');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('16', '432156789');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('16', '789654321');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('17', '789654321');
INSERT INTO `university`.`applications` (`idResearch`, `idProf`) VALUES ('17', '432156789');

最佳答案

查询中的语法没有问题,可能是数据问题。

在执行插入查询之前,请检查以下内容

  • 表 'research' 和列 'idResearch' 存在
  • 表 'professor' & 列 'idProf' 存在
  • 列 idResearch、idProf 的引用值(在插入查询中)应该存在于研究表和教授表中。

  • 手动截断\删除并删除“应用程序”表,然后再次创建它。然后执行您的插入查询。

    关于mysql - SQL 错误代码 1054 未知列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30643407/

    10-11 02:56