Ich verwende mysql_workbench
, um Datenbank zu erstellen Ich habe products_types
, categories
und subcategories
Tabelle. category_id
und subcategory_id
sind die Fremdschlüssel, die auf categories
bzw. subcategories
Tabelle verweisen. Wenn, wenn ich dieses Modell workbench
-mysql database on phpMyAdmin
forward engineer
gibt es Fehler alsdoppelte Schlüssel in Tabelle für Fremdschlüssel in SQL
Can't write; duplicate key in table 'product_types'
Dies ist der genaue Code zusammen mit Fehlern.
Executing SQL script in server
ERROR: Error 1022: Can't write; duplicate key in table 'product_types'
SQL Code:
-- -----------------------------------------------------
-- Table `argo_project_01_2`.`product_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `argo_project_01_2`.`product_types` (
`id` INT NOT NULL,
`category_id` INT NULL,
`subcategory_id` INT NULL,
`title` VARCHAR(100) NULL,
`description` TEXT NULL,
`status` INT NULL DEFAULT 0,
`created` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
`modified` TIMESTAMP NULL,
PRIMARY KEY (`id`),
INDEX `category_id_idx` (`category_id` ASC),
INDEX `subcategory_id_idx` (`subcategory_id` ASC),
CONSTRAINT `category_id`
FOREIGN KEY (`category_id`)
REFERENCES `argo_project_01_2`.`categories` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `subcategory_id`
FOREIGN KEY (`subcategory_id`)
REFERENCES `argo_project_01_2`.`subcategories` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 9 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Was ist falsch in der Abfrage?
Ist das alles, was du tust? Sie explodiert, bevor Sie versuchen, Daten hinzuzufügen? Und Sie haben noch keine Tabelle namens product_types? – Jonny
Nein Ich habe keine 'product_types' Tabellen, aber' categories' und 'subcategories' existieren –
Haben Sie versucht, die Einschränkungen (beide) vom Fremdschlüssel zu unterscheiden? – jonju