我使用MySQL Workbench爲數據庫生成圖表和代碼。MySQL錯誤:無法創建表(錯誤:121「寫入或更新時出現重複鍵」)
當我把代碼到phpMyAdmin,它顯示錯誤(#1005 - 無法創建表wypozyczalnia
wypozyczenie
(錯誤:121 「上寫或更新重複鍵」))
在哪裏問題是什麼? :( 外鍵 - 表wypozyczenie
錯誤是由這部分代碼:
CREATE TABLE IF NOT EXISTS `wypozyczalnia`.`wypozyczenie` (
`id_wyp` INT NOT NULL,
`data_wyp` DATE NOT NULL,
`data_odd` DATE NOT NULL,
`id_samochod` INT NOT NULL,
`id_klient` INT NOT NULL,
`id_pracownik` INT NOT NULL,
`id_plac_wyp` INT NOT NULL,
`id_plac_odd` INT NULL,
`cena` INT NULL,
`kaucja` INT NULL,
PRIMARY KEY (`id_wyp`),
INDEX `id_klient_idx` (`id_klient` ASC),
INDEX `id_samochod_idx` (`id_samochod` ASC),
INDEX `id_placowka_idx` (`id_plac_odd` ASC),
INDEX `id_pracownik_idx` (`id_pracownik` ASC),
INDEX `id_plac_wyp_idx` (`id_plac_wyp` ASC),
CONSTRAINT `id_klient_klient`
FOREIGN KEY (`id_klient`)
REFERENCES `wypozyczalnia`.`klient` (`id_klient`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `id_samochod_samochody`
FOREIGN KEY (`id_samochod`)
REFERENCES `wypozyczalnia`.`samochody` (`id_samochod`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `id_placowka_placowka`
FOREI[...]
由於錯誤消息sa y:你必須兩次使用相同的約束名稱。約束甚至可能在不同的表格中。 – Shadow