的問題是,您的表格被稱爲category
(單數),並且您正在嘗試引用表categories
(複數),最重要的是,您沒有使用表product_category中的字段名稱。
看到下面的例子,你想要什麼。 (我已經從product_category中更改了字段名稱,以便更清楚地在哪裏使用)。
mysql> create table category (cat_id int, category varchar(200));
Query OK, 0 rows affected (0.39 sec)
mysql> create table products (prod_id int, product varchar(200));
Query OK, 0 rows affected (0.40 sec)
mysql> create table product_category (pc_prod_id int, pc_cat_id int);
Query OK, 0 rows affected (0.13 sec)
mysql> alter table product_category add foreign key (pc_cat_id) references category(cat_id);
Query OK, 0 rows affected (0.42 sec)
Records: 0 Duplicates: 0 Warnings: 0