title: Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint 'ekdromes_ibfk_1' in the referenced table 'pwlhseis'
body: <p>I have these two tables:</p>
  
  <pre><code>create table pwlhseis(
  ma int,
  hmeromhnia date,
  wra time,
  hmer_diek date,
  ae_po int,
  amka_po int,
  constraint foreign key (amka_po) references pelates(amka),
  primary key (ma));
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>create table ekdromes(
  ae int,
  diarkeia int,
  proorismos varchar(20),
  kostos float,
  timh float,
  afeteria varchar(20),
  hm_enarkshs date,
  primary key (ae));
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>alter table ypallhloi 
    add constraint foreign key (arithmos_up) references grafeia(arithmos_g);
  
  alter table ekdromes 
    add constraint foreign key (ae) references pwlhseis(ae_po);
  </code></pre>
  
  <p>The first alter works well, when I try to run the second one i get that 1822 error. What is the problem?</p>