0

I have one table called 'taxanomy'

CREATE TABLE `taxanomy`(
    id int not null AUTO_INCREMENT,
    title varchar(255) not null,
    type varchar(255) not null,
    PRIMARY KEY(id, title)
);

And another one called 'taxanomy_relationship'

CREATE TABLE taxanomy_relationship(
    id INT AUTO_INCREMENT,
    post_id int not null,
    title varchar(255) not null,
    PRIMARY KEY(id),
    FOREIGN KEY (title) 
        REFERENCES taxanomy(title) 
        ON DELETE CASCADE 
        ON UPDATE CASCADE
);

In 'taxanomy' table i have two primary key column (id, title).
what i want to do is that to make a connection between "title columns" in both tables with primary key and foreign key but when i want to create it, it throws an error:

1005 - Can't create table taxanomy_relationship (errno: 150 "Foreign key constraint is incorrectly formed")

WHY?

Community
  • 1
  • 1
vahid
  • 171
  • 5
  • Did you mean `FOREIGN KEY(taxanomy_id) REFERENCES taxanomy(id)` ? It's how you'd more normally express a relationship.. ps; taxonomy has 2 O and 1 A – Caius Jard Jan 15 '20 at 13:22
  • Title needs to be a unique/primary key or the left most node of a compound key. – P.Salmon Jan 15 '20 at 13:29
  • And you probably want to reference the id as foreign key, not the title. – Shadow Jan 15 '20 at 13:43

0 Answers0