title: Creating table with 2 froeign keys not working in MySQL
body: <p>I am trying to create 2 tables in MySQL with the below mentioned script but the second query fails with: </p>
  
  <blockquote>
    <p>Error Code: 1215. Cannot add foreign key constraint.</p>
  </blockquote>
  
  <p>Is it because I am linking 2 columns in <strong>emergency_contact_tbl</strong> with single column in <strong>userinfo</strong> table?</p>
  
  <p>How else could I create this relationship in the database?</p>
  
  <pre><code>CREATE  TABLE IF NOT EXISTS  `userinfo` (
    `userid` INT,
    `name` VARCHAR(45),
    PRIMARY KEY (`userid`) )
  
  CREATE  TABLE IF NOT EXISTS `emergency_contact_tbl` (
    `userid` INT NOT NULL ,
    `emergency_contact_personid` INT NOT NULL ,
    INDEX `emergency_contact_tbl_idx` (`userid` ASC, `emergency_contact_personid` ASC) ,
    CONSTRAINT `emergency_contact_tbl_cons`
      FOREIGN KEY (`userid` , `emergency_contact_personid` )
      REFERENCES `userinfo` (`userid` , `userid` )
      ON DELETE CASCADE
      ON UPDATE CASCADE)
  </code></pre>