当我尝试删除作为其他表的外键的列时遇到问题。列是错误创建的。
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/