无法在MySQL中删除外键 [英] Can't Drop foreign key in MySQL

查看:473
本文介绍了无法在MySQL中删除外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在课程和讲师之间有一对多的关系,我想放弃.当我尝试在课程表中删除讲师ID时,它告诉了我.我无法删除它,因为它是外键.然后我决定像这样丢弃它:

I have had a 1 to many relationship between course and instructor, which I wanted to drop. When I tried to drop the instructorID in course table it told me that. I couldn't drop it as it was a foreign key. Then I decided to drop it like this:

ALTER TABLE course DROP FOREIGN KEY instructorID

但是我得到这个错误:

#1091 - Can't DROP 'InstructorID'; check that column/key exists 

我不明白这个错误的意思.我究竟做错了什么?

I don't get what this error means. what am i doing wrong?

推荐答案

请运行SHOW CREATE TABLE course;以确保教师ID是外键 constraint 的名称.

Please run an SHOW CREATE TABLE course; to make sure instructorID is the name of foreign key constraint.

其他: 该错误意味着MySQL搜索名为"InstructorID"的外键约束,但没有这样的约束,也许这是您的列名,但是您必须使用约束名来删除外键.

Additional: The error means MySQL searches for a foreign key constraint named "InstructorID" but there is no constraint with such name, maybe this is your column name, but you have to use the constraint name to delete foreign keys.

这篇关于无法在MySQL中删除外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆