  
<div id="snippet_268" class="snippet">
  <h2><a href="/snippets/268-Fix-for-mysql-error-1005-errno-150-" title="Fix for &quot;mysql error 1005 (errno: 150) &quot; - SQL - mysql, sql, fix, problem, 150">Fix for "mysql error 1005 (errno: 150) "</a></h2>
  <div class="details">
    <a style="background-color: #FFFF94;" href="http://snippets.aktagon.com/languages/134-SQL">
      SQL</a> posted about 1 year ago by christian
          
  </div>

  <div class="body">
    <p>There are at least three reasons, that I know of, to why you could be seeing <a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html" title="errno: 150">mysql error 1005</a></p>


	<ul>
	<li>Adding a foreign key constraint when column types don&#8217;t match</li>
		<li>Not enough privileges to execute the script</li>
		<li>Trying to delete an index that is needed by some other index or constraint (&#8220;error on rename of&#8221;)</li>
	</ul>


	<p>Use &#8220;SHOW  ENGINE INNODB STATUS ;&#8221; to view the error:
<pre class="active4d"><span class="line-numbers">   1 </span> <span class="Keyword">ALTER</span> <span class="Keyword">TABLE</span> videos ADD <span class="Storage">constraint</span> fk_videos_channels_id <span class="Storage">FOREIGN KEY</span> (channel_id) <span class="Storage">REFERENCES</span> channels (id);
<span class="line-numbers">   2 </span> SHOW ENGINE INNODB STATUS;
</pre></p>
  </div>

  <div style="font-size: 0.8em;margin:0.5em;">
    
      Tagged <a href="/tags/71-mysql">mysql</a>, <a href="/tags/255-sql">sql</a>, <a href="/tags/551-fix">fix</a>, <a href="/tags/432-problem">problem</a>, <a href="/tags/603-150">150</a>
    
    
  </div>
</div>






