title: Error Code 1215. Cannot add foreign key constraint for my tables
body: <p>I'm trying to write a script for SQL for adding 2 tables and adding another table that references both tables through a foreign key. I keep getting an error from the 'Enrolls' table. It says foreign key cannot be create.</p>
  
  <p>Here are the tables. </p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `homework7`.`Section` (
    `CourseNo` INT NOT NULL,
    `SectionNo` INT NOT NULL,
    `Instructor` VARCHAR(45) NULL,
    PRIMARY KEY (`CourseNo`, `SectionNo`),
    FOREIGN KEY (`CourseNo`) REFERENCES Course(`CourseNo`));
  
  CREATE TABLE IF NOT EXISTS `homework7`.`Student` (
    `SSN` INT NOT NULL,
    `FirstName` VARCHAR(45) NULL,
    `LastName` VARCHAR(45) NULL,
    `Street` VARCHAR(45) NULL,
    `City` VARCHAR(45) NULL,
    `State` VARCHAR(2) NULL,
    `Zip` INT NULL,
     PRIMARY KEY (`SSN`));
  </code></pre>
  
  <p>Here's the one I'm having trouble with.</p>
  
  <pre><code>  CREATE TABLE IF NOT EXISTS `homework7`.`Enrolls` (
    `SSN` INT NOT NULL,
    `CourseNo` Int NOT NULL,
    `SectionNo` INT NOT NULL,
    PRIMARY KEY (`SSN`, `SectionNo`, `CourseNo`),
    FOREIGN KEY (`SSN`) REFERENCES Student(`SSN`),
    FOREIGN KEY (`CourseNo`) REFERENCES Section(`CourseNo`),
    FOREIGN KEY (`SectionNo`) REFERENCES Section(`SectionNo`));
  </code></pre>
  
  <p>Also the schema is here.
  <a href="https://imgur.com/a/fTg5O" rel="nofollow noreferrer">http://imgur.com/a/fTg5O</a></p>
  
  <p>So should 
  Enrolls (CourseNo) reference Course (CourseNo) or Section (CourseNo)?</p>