title: MySQL: foreign key constraint not working
body: <p>I have a table, <code>companies_employers</code>, with one foreign key, <code>company_id</code>, which references <code>id</code> in <code>companies table</code>.</p>
  
  <pre><code>CREATE TABLE `companies_employers` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `first_name` varchar(100) DEFAULT NULL,
      `last_name` varchar(100) DEFAULT NULL,
      `company_id` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`),
      KEY `company_id` (`company_id`),
      CONSTRAINT `companies_employers_ibfk` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
  </code></pre>
  
  <p>I populate <code>companies_employers</code> and then run:</p>
  
  <pre><code>SELECT * FROM companies_employers
  </code></pre>
  
  <p><code>company_id</code> is empty.</p>
  
  <p>Now I run:</p>
  
  <pre><code>SELECT company_id FROM `companies_employers`
  </code></pre>
  
  <p>Working, it gives the correct value.</p>
  
  <p>Why can't I get it with <code>SELECT * FROM companies_employers</code>? Can someone explain this?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Screenshots from the scenarios:</p>
  
  <p><a href="https://i.stack.imgur.com/8xeDE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8xeDE.png" alt="SELECT * FROM companies_employers"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Ox2af.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ox2af.png" alt="SELECT company_id FROM &lt;code&gt;companies_employers&lt;/code&gt;"></a></p>
  
  <p><a href="https://i.stack.imgur.com/nFHgy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nFHgy.png" alt="Update field"></a></p>