title: Adding foreign key Error 150
body: <p>Ok look I know there are many questions out there about error 150.</p>
  
  <p>But as SO says, " If those answers do not fully address your question, please ask a new question."  so i am asking a new question.</p>
  
  <p>I have two tables tableA and tableB, both engine are innoDB</p>
  
  <p>My query <code>alter table tableA add foreign key (url) references tableB(url)</code>
  gives <code>Error 1005 (HY000): can't create table myDatabaseName.#sql-3134 e52(error 150)</code></p>
  
  <p>So here's what i did.</p>
  
  <pre><code>alter tableA drop column url;
  alter tableA add column url varchar(100) NOT NULL default "";
  alter tableB drop column url;
  alter tableB add column url varchar(100) NOT NULL default "";
  alter tableB add primary key (url,bName,pID);
  
  alter tableA engine = innodb;
  alter tableB engine = innodb;
  </code></pre>
  
  <p>to confirm i checked <code>SHOW TABLE STATUS</code> both gave same innoDB engine</p>
  
  <p>Then I tried again same query but same error.
  So here's the situation so far</p>
  
  <ul>
  <li>both tables are using same engine</li>
  <li>both tables have compatible column url same datatype <code>varchar(100) NOT NULL default ""</code></li>
  </ul>
  
  <p><code>show create table tableA</code> gives;</p>
  
  <pre><code>CREATE TABLE `tableA` (
  `url` varchar(100) NOT NULL DEFAULT '',
  `tNo` int(11) NOT NULL,
  `bName` varchar(40) NOT NULL,
  `pID` int(11) NOT NULL,
  `oprNo` int(11) DEFAULT NULL,
  `found` int(11) DEFAULT NULL,
  `fix` int(11) DEFAULT NULL,
  `fixStatus` varchar(40) DEFAULT NULL,
  `fixDate` date DEFAULT NULL,
  `releaseStatus` varchar(40) DEFAULT NULL,
  `releaseDate` date DEFAULT NULL,
  PRIMARY KEY (`url`,`tNo`),
  CONSTRAINT `tableA_ibfk_1` FOREIGN KEY (`url`) REFERENCES `tableB` (`url`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  </code></pre>
  
  <p><code>show create table tableB</code> gives</p>
  
  <pre><code> CREATE TABLE `tableB` (
    `url` varchar(100) NOT NULL DEFAULT '',
    `bName` varchar(40) NOT NULL,
    `pID` int(11) NOT NULL,
    PRIMARY KEY (`url`,`bName`,`pID`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  </code></pre>
  
  <p><strong>update</strong>
  I was able to add one foreign key url using mysql workbench
  But same error is coming for other fields<br></p>
  
  <pre><code> `alter table tableA add foreign key (bName) references tableB(bName)`&lt;br&gt;
   `alter table tableA add foreign key (pID) references tableB(pID)`
  </code></pre>