MySQL 我收到错误:列上缺少索引。当我尝试在 phpMyAdmin Designer 工具中创建表之间的关系时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49094502/
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
I'm getting Error: Missing index on column(s). when I try to create a relationship between tables in phpMyAdmin Designer tool
提问by Bobimaru
I need to create the database schema and include it in my software requirements specification for my school project, however, when I try to create a relationship between 2 tables, I get Error: Missing index on column(s).
我需要创建数据库模式并将其包含在我的学校项目的软件需求规范中,但是,当我尝试在 2 个表之间创建关系时,出现错误:列缺少索引。
回答by Isaac Bennetch
I think @HazarathChillara has this right; you need to create primary, unique, or index keys.
我认为@HazarathChillara 有这个权利;您需要创建主键、唯一键或索引键。
You said every table has an primary key, but did you make each foreign and referenced key an index as well? It sounds like you neglected to properly set up your table structure; I only get the error when I don't have a primary key or index on the particular columns I'm working with.
您说每个表都有一个主键,但是您是否也将每个外键和引用键都设为索引?听起来您忽略了正确设置表结构;我只在我正在处理的特定列上没有主键或索引时才会收到错误消息。
“ MySQL 需要外键和引用键的索引,以便外键检查可以快速并且不需要表扫描”
You can just put an INDEX on the foreign key (often my referenced key is a primary key anyway, so I don't need any additional key on that column).
您可以在外键上放置一个 INDEX(通常我引用的键无论如何都是主键,所以我不需要该列上的任何其他键)。
回答by usman khan
This error appears only when you neglect table structure. Make sure that you Indexed a foreign key as well. you can see i marked how could i select my foreign key as index.In this Image I am indexing selected, 'sr' my foreign key
仅当您忽略表结构时才会出现此错误。确保您也索引了外键。你可以看到我标记了如何选择我的外键作为索引。在此图像中,我选择了索引,'sr' 我的外键