我没有练过SQL在一段时间,我忘了如何将外键添加到我的表添加一个外键的表
mysql> alter table students
add foreign key fk_unit(unitid)
references unit(unitid)
on delete no action
on update cascade;
ERROR 1072 (42000): Key column 'unitid' doesn't exist in table
我不知道为什么是这样的话?我的单元表有一个名为unitid的主键,为什么这会继续发生?
你在学生表中有相同名称的column unitid检查它。我认为这是不同的,这就是为什么给错误。 –
您的单元表有一列unitid,但可能是您的学生表没有列名unitid。这就是错误所暗示的。 –