To define a foreign key
on a column its parent referenced field must be indexed.
As per documentation on foreign key
constraints:
REFERENCES tbl_name (index_col_name,...)
Define an INDEX
on value
in table proba
and it should be working.
CREATE TABLE IF NOT EXISTS `mydb`.`proba` (
`key` VARCHAR(255) NOT NULL,
`value` VARCHAR(255) NOT NULL,
KEY ( `value` ), -- <-------- this line was missing
PRIMARY KEY (`key`, `value`))
ENGINE = InnoDB;
Once you define a KEY
on the parent column, a foreign key column in zavisnost
table can refer it, like.
...
FOREIGN KEY (`key`)
REFERENCES `mydb`.`proba` (`value`)
...
Refer to:
[CONSTRAINT [symbol]] FOREIGN KEY
[index_name] (index_col_name, ...)
REFERENCES tbl_name (index_col_name,...)
[ON DELETE reference_option]
[ON UPDATE reference_option]reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION