title: "Key column doesn't exist in table" when trying to define FOREIGN KEY
body: <p>I'm trying to setup a MySQL-Script that creates 5 tables. In three tables, there is a <code>FOREIGN KEY</code>, and for all three of them the same error appears:</p>
  
  <pre><code>Error Code: 1072. Key column ... doesn't exist in table
  </code></pre>
  
  <p>whereas ... are <code>Gebaeude</code>, <code>Dept_Name</code> and <code>Mat_Nr</code></p>
  
  <p>Here's the script</p>
  
  <pre><code>use cs261_24;
  
  drop table if exists Professor;
  drop table if exists Departement;
  drop table if exists Gebaeude;
  drop table if exists Student;
  drop table if exists Pruefung;
  
  
  CREATE TABLE Gebaeude (
                          Gebaeude    VARCHAR(20) NOT NULL PRIMARY KEY,
                          Hauswart    VARCHAR(20) NOT NULL,
                          Adresse     VARCHAR(20) NOT NULL
  )engine = innodb;
  
  CREATE TABLE Professor  (
                          P_ID        INTEGER PRIMARY KEY CHECK (P_ID &gt; 0),
                          P_Name      VARCHAR(20) NOT NULL,
                          Dept_Name   VARCHAR(20) NOT NULL,
                          Raum        INTEGER UNIQUE CHECK (Raum &gt; 0),
                          Tel         INTEGER(10) UNIQUE CHECK (Tel &gt; 210000000),
                          FOREIGN KEY (Gebaeude) REFERENCES Gebaeude (Gebaeude) 
  )engine = innodb;
  
  CREATE TABLE Departement (
                          Dept_Name   VARCHAR(20) NOT NULL PRIMARY KEY,
                          Vorsteher   VARCHAR(20) NOT NULL
  )engine = innodb;
  
  CREATE TABLE Student (
                          Mat_Nr      INTEGER(8) PRIMARY KEY CHECK (Mat_Nr &gt; 0),
                          S_Name      VARCHAR(20) NOT NULL,
                          Semester    INTEGER CHECK(Semester &gt; 0),
                          FOREIGN KEY (Dept_Name) REFERENCES Departement (Dept_Name) 
  )engine = innodb;
  
  CREATE TABLE Pruefung (
                          Pr_ID       INTEGER PRIMARY KEY CHECK(Pr_ID &gt; 0),
                          Fach        VARCHAR(20) NOT NULL,
                          Pruefer     VARCHAR(20) NOT NULL,
                          Note        FLOAT CHECK (Note &gt;= 1 AND Note &lt;= 6),
                          FOREIGN KEY (Mat_Nr) REFERENCES Student (Mat_Nr)
  )engine = innodb;
  </code></pre>
  
  <p>Why? I work with MySQL Workbench, and I clearly see the created tables, plus the specific columns are marked as primary keys!</p>