Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm getting Error: Missing index on column(s). when I try to create a relationship between tables in phpMyAdmin Designer tool

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).

like image 291
Bobimaru Avatar asked Mar 04 '18 10:03

Bobimaru


2 Answers

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

like image 45
usman khan Avatar answered Sep 21 '22 07:09

usman khan


I think @HazarathChillara has this right; you need to create primary, unique, or index keys.

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 requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan"

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).

like image 73
Isaac Bennetch Avatar answered Sep 25 '22 07:09

Isaac Bennetch