I use MySQL Workbench to generate diagram and code for database.
我使用MySQL Workbench为数据库生成图表和代码。
When I put code to phpMyAdmin, it show error (#1005 - Can't create table wypozyczalnia
.wypozyczenie
(errno: 121 "Duplicate key on write or update"))
当我将代码放到phpMyAdmin时,它会显示错误(#1005 -无法创建表wypozyczalnia)。wypozyczenie (errno: 121“写或更新的复制键”)
Where is the problem? :( Foreign Keys - table wypozyczenie
问题在哪里?:(外键-表wypozyczenie
Error is from this part of code:
错误来自于代码的这一部分:
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[...]
1 个解决方案
#1
2
As the error message says: you must have used the same constraint name twice. The constraint may even be in a different table, since the constraint name must be unique in a database:
正如错误消息所说:您必须使用相同的约束名称两次。约束甚至可能位于另一个表中,因为约束名称必须在数据库中是唯一的:
CONSTRAINT symbol
约束的象征
If the CONSTRAINT symbol clause is given, the symbol value, if used, must be unique in the database. A duplicate symbol results in an error. If the clause is not given, or a symbol is not included following the CONSTRAINT keyword, a name for the constraint is created automatically.
如果给定了约束符号子句,则符号值(如果使用的话)在数据库中必须是唯一的。重复的符号会导致错误。如果没有给定子句,或者约束关键字后面没有包含符号,则会自动创建约束的名称。
#1
2
As the error message says: you must have used the same constraint name twice. The constraint may even be in a different table, since the constraint name must be unique in a database:
正如错误消息所说:您必须使用相同的约束名称两次。约束甚至可能位于另一个表中,因为约束名称必须在数据库中是唯一的:
CONSTRAINT symbol
约束的象征
If the CONSTRAINT symbol clause is given, the symbol value, if used, must be unique in the database. A duplicate symbol results in an error. If the clause is not given, or a symbol is not included following the CONSTRAINT keyword, a name for the constraint is created automatically.
如果给定了约束符号子句,则符号值(如果使用的话)在数据库中必须是唯一的。重复的符号会导致错误。如果没有给定子句,或者约束关键字后面没有包含符号,则会自动创建约束的名称。