I'm trying to create a many to many relation table for products
and categories
named product_categories
.
Using: MySQL, INNODB.
IDs are UUID4 ,using char(36)
for the ID fields.
create table product_categories
(
product_id char(36) not null,
category_id char(36) not null,
primary key (product_id, category_id),
constraint fk_product_categories_category
foreign key (category_id) references categories (id)
on delete cascade,
constraint fk_product_categories_product
foreign key (product_id) references products (id)
on delete cascade
);
Problem seems to be category_id
as if I remove it, the table is created without a problem.
Category table is also matching the ID;
CREATE TABLE `categories` (
`id` char(36) NOT NULL,
....
)
Unfortunately I still get the following error;[HY000][1005] Can't create table product_categories (errno: 150 "Foreign key constraint is incorrectly formed")
. What am I missing here?