title: Adding foreign key to existing MySQL table via command line
body: <p>I am trying to add a foreign key to a table i've created in the terminal.</p>
  
  <p>I've tried</p>
  
  <pre><code>ALTER TABLE table_name FOREIGN KEY key_name REFERENCES table_name1(key_name);
  </code></pre>
  
  <p>and </p>
  
  <pre><code>ALTER TABLE table_name ADD FOREIGN KEY key_name REFERENCES table_name1(key_name);
  </code></pre>
  
  <p>but keep getting the same error message that tells me my syntax is wrong.</p>
  
  <p>Most of the questions related to this, though helpful, they don't talk about how to add a foreign key in the terminal.</p>