mysql - 从 MySQL 中删除外键

标签 mysql foreign-keys key primary-key

当我尝试删除作为其他表的外键的列时遇到问题。列是错误创建的。

First table 'users' with Columns 'ID (Primary key)','user_rest_id(Foreign key)'
Second table 'rest' with Columns 'ID (Primary key)','user_id(Foreign key)'

我正在尝试删除“user_rest_id”列。我错误地创建了它,它与表“rest”“ID”连接。

在列下降时:

#1553 - Cannot drop index 'user_rest_id': needed in a foreign key constraint.

当我尝试删除外键时,它显示:

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

最佳答案

假设您已经使用约束创建了外键。

ALTER TABLE users
DROP FOREIGN KEY fk_users; //Your actual constraint name

希望这有帮助。

关于mysql - 从 MySQL 中删除外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27633915/

相关文章:

javascript - JQuery 函数在输入键时不触发

java - CF "for"循环占用内存/cpu

PHP - POST 表单不会为复选框传递数值,但接受所有其他值

sql - 在 PostgreSQL 中删除带有外键的行

python - Django 模型 : mutual references between two classes and impossibility to use forward declaration in python

java - 没有明确答案 : Which Java Map is the cheapest?

php - mysql 到 mysqli 连接代码失败?

mysql - 在 MySQL 中,我们什么时候应该使用 IF() 而不是 CASE...WHEN,反之亦然?

sql - 多对多关系数据库设计

git - 如何使用私钥克隆 GIT 存储库