I am trying to create tables for a database. Everything is fine except for when I try to make my last joining table, it keeps giving me a foreign key error "Create table 'refactor_test/ads_categories' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns."
Here are the parameters I used to create each table, the one that keeps throwing errors is ads_categories:
create table ads
(
id int unsigned not null auto_increment,
user_id int unsigned not null,
title varchar(100) not null,
description varchar(500),
primary key (id),
foreign key (user_id) references refactor_test.users (id)
);
create table users
(
id int unsigned not null auto_increment,
username varchar(25) not null,
password varchar(100) not null,
email varchar(40) not null,
primary key (id)
);
create table categories
(
id int unsigned auto_increment not null,
category varchar(50) not null,
category_id int unsigned not null,
primary key (id)
);
create table ads_categories
(
id int unsigned auto_increment not null,
ad_id int unsigned not null,
ad_category int unsigned not null,
primary key (id),
foreign key (ad_id) references refactor_test.ads (id),
foreign key (ad_category) references refactor_test.categories (category_id)
);