php 删除phpmyadmin上的外键表?不能删除索引:在外键约束中需要

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25626045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:55:09  来源:igfitidea点击:

Deleting foreign key tables on phpmyadmin? cannot drop index: needed in foreign key constraint

phpsqlphpmyadmin

提问by Poe

I've been trying to find a way to delete some foreign keys generated by mistake, but each time I DROP the table associated with the foreign key to try and erase it, it says "cannot drop index: needed in foreign key constraint".

我一直试图找到一种方法来删除一些错误生成的外键,但是每次我删除与外键关联的表以尝试擦除它时,它都会显示“无法删除索引:需要在外键约束中”。

回答by johanvs

In "Structure" tab, click on "see relational view" below the fields. Here you can remove the foreign keys by selecting an empty value in the dropdown.

在“结构”选项卡中,单击字段下方的“查看关系视图”。在这里,您可以通过在下拉列表中选择一个空值来删除外键。

回答by Cfreak

You have to delete the foreign key with an alter statement:

您必须使用更改语句删除外键:

ALTER TABLE yourtable DROP CONSTRAINT yourforeignkeyname

You might be able to force drop it as well (works in the MySQL console but might not work in phpmyadmin as I'm not sure how sessions are handled)

您也可以强制删除它(在 MySQL 控制台中有效,但在 phpmyadmin 中可能无效,因为我不确定会话是如何处理的)

SET FOREIGN_KEY_CHECKS=0; DROP TABLE yourtable;

Note: this is very dangerous and not recommended if you're seriously using foreign keys.

注意:这是非常危险的,如果您认真使用外键,不建议这样做。