Referencing multiple tables in mysql
<p>How do I reference multiple tables for one table ?</p>

<p>In the assignment, I have to create 5 tables with each table having <code>INT id:
Owners, homes, home_owners, installation, house_type</code>.
Owners can have multiple homes and homes can have multiple owners.
Home needs to have installations and house_type(both need to be <code>VARCHAR</code> type).</p>

<p>I wrote this to sql but it returns an </p>

<blockquote>
  <p>error: errno: 150 "Foreign key constraint is incorrectly formed"</p>
</blockquote>

<pre><code>CREATE TABLE owners (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
created DATETIME,
modified DATETIME
);

CREATE TABLE homes (
id INT AUTO_INCREMENT PRIMARY KEY,
created DATETIME,
modified DATETIME,
home_types_group VARCHAR(255) NOT NULL
);

CREATE TABLE home_owners (
id INT AUTO_INCREMENT PRIMARY KEY,
created DATETIME,
modified DATETIME,
owners_num INT NOT NULL,
FOREIGN KEY owners_num_key (owners_num) REFERENCES owners(id)
);

CREATE TABLE installation (
id INT AUTO_INCREMENT PRIMARY KEY,
brands VARCHAR(255) NOT NULL,
created DATETIME,
modified DATETIME,
FOREIGN KEY brands_key (brands)  REFERENCES homes(home_types_group)
);

CREATE TABLE types (
id INT AUTO_INCREMENT PRIMARY KEY,
types VARCHAR(255) NOT NULL,
created DATETIME,
modified DATETIME,
FOREIGN KEY brands_key (types)  REFERENCES homes(home_types_group)
);
</code></pre>