There are two tables, items and format_file .

items :

enter image description here

format_file :

enter image description here

I make connections between items.id_format_file and format_file.id .

enter image description here

But when I add two records with the same file format, this error pops up, I work in HeidiSQL .

enter image description here

Result SHOW CREATE TABLE items

  CREATE TABLE `items` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `name` char(255) NOT NULL, `link` text NOT NULL, `owner` char(255) DEFAULT NULL, `date_start` date DEFAULT NULL, `date_end` date DEFAULT NULL, `description` mediumtext, `id_format_file` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id_format_file` (`id_format_file`), CONSTRAINT `FK_items_format_file` FOREIGN KEY (`id_format_file`) REFERENCES `format_file` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 
  • one
    execute the SHOW CREATE TABLE items command and show the result - plesser
  • the result was added at the end of the question - Maxim Kokhansky
  • one
    actually logical ..... UNIQUE KEY id_format_file field value should be unique - Alexey Shimansky

1 answer 1

Here is the answer to your problem.

 UNIQUE KEY `id_format_file` (`id_format_file`), 

you set a requirement to check the uniqueness of the record and therefore you cannot record the record with the same key