title: Failed to add the foreign key constraint. Missing index for constraint ' ' in the referenced table ' '
body: <p>When I try to upload this code below to MySQL server I get the error</p>
  <blockquote>
  <p>#1822 - Failed to add the foreign key constraint. Missing index for constraint 'productselectronics_ibfk_1' in the referenced table
  'products'</p>
  </blockquote>
  <pre><code>create table Shops(
      distance integer,
      num_workers integer,
      name varchar(20),
      id varchar(8) unique not null,
      store_type varchar(30),
      primary key(id)
  );
  
  create table Workers(
      id varchar(8) unique not null,
      name varchar(20),
      position varchar(20),
      primary key(id)
  );
  create table Products(
      id varchar(8) unique not null,
      name varchar(40),
      price double precision(7, 2),
      description varchar(255),
      availability boolean,
      num_in_stock integer,
      primary key(id)
  );
  
  create table ProductsElectronics(
      product_id varchar(8) unique not null,
      product_name varchar(40),
      foreign key(product_id, product_name) references Products(id, name),
      
      brand_name varchar(20)
  );
  
  </code></pre>
  <p>I don't really ask questions here, I rather prefer to google it on my own, but I could not find the solution anywhere. Other solutions on SO did not work for me.</p>