SQLError - create foreign key

При попытке добавить внешний ключ вылетела ошибка

введите сюда описание изображения

До этого были произведены следующие действия (Действовал согласно https://folkprog.net/sozdanie-svyazey-phpmyadmin/.)

maintable

subordinatetable

Запрос на создание FK - Error text:

ALTER TABLE monoblocks ADD FOREIGN KEY (image_id) REFERENCES monoblock_images(id) ON DELETE RESTRICT ON UPDATE RESTRICT;

#1452 - Cannot add or update a child row: a foreign key constraint fails (myishop.#sql-2150_93, CONSTRAINT #sql-2150_93_ibfk_21 FOREIGN KEY (image_id) REFERENCES monoblock_images (id))

Пытался выполнить SHOW CREATE TABLE monoblocks и получил следующий результат (в sql новичок - поэтому не серчайте)

введите сюда описание изображения

Нашел

CREATE TABLE `monoblock_images` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `path_to_image` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

CREATE TABLE `monoblocks` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `goods_id` int(11) NOT NULL,
 `screendiagonal_id` int(11) NOT NULL,
 `cpu_id` int(11) NOT NULL,
 `ramsize_id` int(11) NOT NULL,
 `os_id` int(11) NOT NULL,
 `hdd_id` int(11) NOT NULL,
 `screenresolution_id` int(11) NOT NULL,
 `matrixtype_id` int(11) NOT NULL,
 `countcpucores` int(11) NOT NULL,
 `videocards_id` int(11) NOT NULL,
 `videocardtypes_id` int(11) NOT NULL,
 `frequency_id` int(11) NOT NULL,
 `ramtype_id` int(11) NOT NULL,
 `oddtype_id` int(11) NOT NULL,
 `bodycolor_id` int(11) NOT NULL,
 `weight` int(11) NOT NULL,
 `wifisupport_id` int(11) NOT NULL,
 `bluetoothsupport_id` int(11) NOT NULL,
 `wifistandard_id` int(11) NOT NULL,
 `bluetoothstandard_id` int(11) NOT NULL,
 `guarantee_id` int(11) NOT NULL,
 `connectorsnumberusb2.0` int(11) NOT NULL,
 `connectorsnumberusb3.0` int(11) NOT NULL,
 `connectorsnumberhdmi` int(11) NOT NULL,
 `microphoneconnecors` int(11) NOT NULL,
 `headphoneconnectors` int(11) NOT NULL,
 `builtinmicrophone` tinyint(1) NOT NULL,
 `builtinspeakers` tinyint(1) NOT NULL,
 `touchscreen` tinyint(1) NOT NULL,
 `webcam` tinyint(1) NOT NULL,
 `keyboard_included` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `mouse_included` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `ssd_volume` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `dimensions` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `image_id` int(11) DEFAULT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `id` (`id`),
 KEY `goods_id` (`goods_id`),
 KEY `screendiagonal_id` (`screendiagonal_id`),
 KEY `cpu_id` (`cpu_id`),
 KEY `ramsize_id` (`ramsize_id`),
 KEY `os_id` (`os_id`),
 KEY `hdd` (`hdd_id`),
 KEY `screenresolution_id` (`screenresolution_id`),
 KEY `matrixtype_id` (`matrixtype_id`),
 KEY `countcpucores` (`countcpucores`),
 KEY `videocards_id` (`videocards_id`),
 KEY `videocardtypes_id` (`videocardtypes_id`),
 KEY `frequency_id` (`frequency_id`),
 KEY `ramtype_id` (`ramtype_id`),
 KEY `oddtype_id` (`oddtype_id`),
 KEY `bodycolor_id` (`bodycolor_id`),
 KEY `wifisupport_id` (`wifisupport_id`),
 KEY `bluetoothsupport_id` (`bluetoothsupport_id`),
 KEY `wifistandard_id` (`wifistandard_id`),
 KEY `bluetoothstandard_id` (`bluetoothstandard_id`),
 KEY `guarantee_id` (`guarantee_id`),
 KEY `image_id` (`image_id`),
 CONSTRAINT `monoblocks_ibfk_1` FOREIGN KEY (`goods_id`) REFERENCES `goods` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_10` FOREIGN KEY (`videocards_id`) REFERENCES `videocards` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_11` FOREIGN KEY (`videocardtypes_id`) REFERENCES `videocardtypes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_12` FOREIGN KEY (`frequency_id`) REFERENCES `cpufrequency` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_13` FOREIGN KEY (`ramtype_id`) REFERENCES `rammemory` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_14` FOREIGN KEY (`oddtype_id`) REFERENCES `oddtype` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_15` FOREIGN KEY (`bodycolor_id`) REFERENCES `mainbodycolor` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_16` FOREIGN KEY (`wifisupport_id`) REFERENCES `wifisupport` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_17` FOREIGN KEY (`bluetoothsupport_id`) REFERENCES `bluetoothsupport` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_18` FOREIGN KEY (`wifistandard_id`) REFERENCES `wifistandard` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_19` FOREIGN KEY (`bluetoothstandard_id`) REFERENCES `bluetoothstandard` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_2` FOREIGN KEY (`screendiagonal_id`) REFERENCES `screendiagonal` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_20` FOREIGN KEY (`guarantee_id`) REFERENCES `guarantee` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_3` FOREIGN KEY (`cpu_id`) REFERENCES `cpus` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_4` FOREIGN KEY (`ramsize_id`) REFERENCES `ramsize` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_5` FOREIGN KEY (`os_id`) REFERENCES `os` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_6` FOREIGN KEY (`hdd_id`) REFERENCES `disksandrives` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_7` FOREIGN KEY (`screenresolution_id`) REFERENCES `screenresolution` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_8` FOREIGN KEY (`matrixtype_id`) REFERENCES `matrixtype` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `monoblocks_ibfk_9` FOREIGN KEY (`countcpucores`) REFERENCES `numbercpucores` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Содержимое таблицы monoblocks следующее

введите сюда описание изображения

Каким образом можно отредактировать image_id в monoblocks?


Ответы (0 шт):