title: Error Code: 1215. Cannot add foreign key constraint (foreign keys)
body: <pre><code>CREATE DATABASE my_db;
  
  CREATE TABLE class (
    classID int NOT NULL AUTO_INCREMENT,
    nameClass varchar(255),
    classLeader varchar(255),
    FOREIGN KEY (classLeader) REFERENCES student(studentID),
    PRIMARY KEY (classID));
  
  CREATE TABLE student (
    studentID int NOT NULL AUTO_INCREMENT,
    lastName varchar(255),
    firstName varchar(255),
    classID int,
    FOREIGN KEY (classID) REFERENCES class(classID),
    PRIMARY KEY (studentID));
  </code></pre>
  
  <p>I am trying to ensure data consistency between the tables by using foreign key so that the DBMS can check for errors; however, it seems we can't do that for some reason. What's the error and is there an alternative? Also, when I fill a table that has a foreign key, I can't fill the field that's reserved for the foreign key(s), right? Also, is a foreign key considered to be a key at all? </p>