我在 Mysql Workbench 中做了一个 ER 图,我正在尝试使用 phpMyAdmin 在我的服务器中加载,但它返回了下一个错误:
Error
SQL Query:
-- ----------------------------------------------------- -- Table `BDA`.`UG` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `BDA`.`UG` ( `numero_ug` INT NOT NULL, `nombre` VARCHAR(45) NOT NULL, `segunda_firma_autorizada` VARCHAR(45) NOT NULL, `fecha_creacion` DATE NOT NULL, `nombre_depto` VARCHAR(140) NOT NULL, `dni` INT NOT NULL, `anho_contable` INT NOT NULL, PRIMARY KEY (`numero_ug`), INDEX `nombre_depto_idx` (`nombre_depto` ASC), INDEX `dni_idx` (`dni` ASC), INDEX `anho_contable_idx` (`anho_contable` ASC), CONSTRAINT `nombre_depto` FOREIGN KEY (`nombre_depto`) REFERENCES `BDA`.`Departamento` (`nombre_depto`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `dni` FOREIGN KEY (`dni`) REFERENCES `BDA`.`Trabajador` (`dni`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `anho_contable` FOREIGN KEY (`anho_contable`) REFERENCES `BDA`.`Capitulo_Contable` (`anho_contable`) [...]
MySQL said: Documentation
#1022 - Can't write; duplicate key in table 'ug'
我将图表的结果从 Mysql Workbench 导出到一个 SQL 文件,这个文件就是我要上传的文件。
这是文件。我找不到重复的密钥。
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
CREATE SCHEMA IF NOT EXISTS `BDA` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `BDA` ;
-- -----------------------------------------------------
-- Table `BDA`.`Departamento`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `BDA`.`Departamento` (
`nombre_depto` VARCHAR(140) NOT NULL,
`area_depto` VARCHAR(140) NOT NULL,
PRIMARY KEY (`nombre_depto`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `BDA`.`Trabajador`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `BDA`.`Trabajador` (
`dni` INT NOT NULL,
`direccion` VARCHAR(140) NOT NULL,
`nombre` VARCHAR(45) NOT NULL,
`apellidos` VARCHAR(140) NOT NULL,
`fecha_nacimiento` DATE NOT NULL,
`fecha_contrato` DATE NOT NULL,
`titulacion` VARCHAR(140) NULL,
`nombre_depto` VARCHAR(45) NOT NULL,
PRIMARY KEY (`dni`),
INDEX `nombre_depto_idx` (`nombre_depto` ASC),
CONSTRAINT `nombre_depto`
FOREIGN KEY (`nombre_depto`)
REFERENCES `BDA`.`Departamento` (`nombre_depto`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `BDA`.`Capitulo_Contable`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `BDA`.`Capitulo_Contable` (
`anho_contable` INT NOT NULL,
`numero_ug` INT NOT NULL,
`debe` DOUBLE NOT NULL,
`haber` DOUBLE NOT NULL,
PRIMARY KEY (`anho_contable`),
INDEX `numero_ug_idx` (`numero_ug` ASC),
CONSTRAINT `numero_ug`
FOREIGN KEY (`numero_ug`)
REFERENCES `BDA`.`UG` (`numero_ug`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `BDA`.`UG`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `BDA`.`UG` (
`numero_ug` INT NOT NULL,
`nombre` VARCHAR(45) NOT NULL,
`segunda_firma_autorizada` VARCHAR(45) NOT NULL,
`fecha_creacion` DATE NOT NULL,
`nombre_depto` VARCHAR(140) NOT NULL,
`dni` INT NOT NULL,
`anho_contable` INT NOT NULL,
PRIMARY KEY (`numero_ug`),
INDEX `nombre_depto_idx` (`nombre_depto` ASC),
INDEX `dni_idx` (`dni` ASC),
INDEX `anho_contable_idx` (`anho_contable` ASC),
CONSTRAINT `nombre_depto`
FOREIGN KEY (`nombre_depto`)
REFERENCES `BDA`.`Departamento` (`nombre_depto`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `dni`
FOREIGN KEY (`dni`)
REFERENCES `BDA`.`Trabajador` (`dni`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `anho_contable`
FOREIGN KEY (`anho_contable`)
REFERENCES `BDA`.`Capitulo_Contable` (`anho_contable`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `BDA`.`Cliente`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `BDA`.`Cliente` (
`cif_cliente` INT NOT NULL,
`nombre_cliente` VARCHAR(140) NOT NULL,
PRIMARY KEY (`cif_cliente`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `BDA`.`Ingreso`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `BDA`.`Ingreso` (
`id` INT NOT NULL,
`concepto` VARCHAR(45) NOT NULL,
`importe` DOUBLE NOT NULL,
`fecha` DATE NOT NULL,
`cif_cliente` INT NOT NULL,
`numero_ug` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `cif_cliente_idx` (`cif_cliente` ASC),
INDEX `numero_ug_idx` (`numero_ug` ASC),
CONSTRAINT `cif_cliente`
FOREIGN KEY (`cif_cliente`)
REFERENCES `BDA`.`Cliente` (`cif_cliente`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `numero_ug`
FOREIGN KEY (`numero_ug`)
REFERENCES `BDA`.`UG` (`numero_ug`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `BDA`.`Proveedor`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `BDA`.`Proveedor` (
`cif_proveedor` INT NOT NULL,
`nombre_proveedor` VARCHAR(140) NOT NULL,
PRIMARY KEY (`cif_proveedor`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `BDA`.`Gasto`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `BDA`.`Gasto` (
`id` INT NOT NULL,
`concepto` VARCHAR(45) NOT NULL,
`importe` DOUBLE NOT NULL,
`fecha` DATE NOT NULL,
`factura` INT NOT NULL,
`cif_proveedor` INT NOT NULL,
`numero_ug` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `cif_proveedor_idx` (`cif_proveedor` ASC),
INDEX `numero_ug_idx` (`numero_ug` ASC),
CONSTRAINT `cif_proveedor`
FOREIGN KEY (`cif_proveedor`)
REFERENCES `BDA`.`Proveedor` (`cif_proveedor`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `numero_ug`
FOREIGN KEY (`numero_ug`)
REFERENCES `BDA`.`UG` (`numero_ug`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
感谢您的建议。