#1005-无法创建表

ltqd579y  于 2022-10-03  发布在  Mysql
关注(0)|答案(3)|浏览(145)

我正试图在我的数据库中创建一些表,但我的phpmyadmin显示错误1005-无法创建表,在表tbapp_por_tbpais上,下面是MySQL,有人能帮我吗?

tbApp

CREATE TABLE IF NOT EXISTS `tbApp` (
  `app_cod` INT NOT NULL,
  `app_nome` VARCHAR(45) NULL,
  `app_cod_do_app` VARCHAR(45) NULL,
  `app_pac_fit_qtde` VARCHAR(10) NULL,
  `app_pac_flex_qtde` VARCHAR(45) NULL,
  `app_pac_mega_qtde` VARCHAR(45) NULL,
  `app_trial` VARCHAR(1) NULL,
  `app_trial_dias` VARCHAR(4) NULL,
  `app_pac_fit_preco` VARCHAR(45) NULL,
  `app_pac_flex_preco` VARCHAR(45) NULL,
  `app_pac_mega_preço` VARCHAR(45) NULL,
  PRIMARY KEY (`app_cod`))
ENGINE = InnoDB;

cupomDesc

CREATE TABLE IF NOT EXISTS `cupomDesc` (
  `cupom_cod` INT NOT NULL,
  `cupom_cod_desc` VARCHAR(45) NULL,
  `cupom_valido_ate` DATETIME NULL,
  `cupom_exp_percent` VARCHAR(45) NULL,
  PRIMARY KEY (`cupom_cod`))
ENGINE = InnoDB;

tela

CREATE TABLE IF NOT EXISTS `tela` (
  `tela_cod` INT NOT NULL,
  `tela_nome` VARCHAR(45) NULL,
  PRIMARY KEY (`tela_cod`))
ENGINE = InnoDB;

tbHelptips

CREATE TABLE IF NOT EXISTS `tbHelptips` (
  `help_cod` INT NOT NULL,
  `help_texto` VARCHAR(45) NULL,
  `tela_tela_cod` INT NOT NULL,
  PRIMARY KEY (`help_cod`),
  INDEX `fk_tbHelptips_tela1_idx` (`tela_tela_cod` ASC),
  CONSTRAINT `fk_tbHelptips_tela1`
    FOREIGN KEY (`tela_tela_cod`)
    REFERENCES `tela` (`tela_cod`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

tbApp_por_tbPais

CREATE TABLE IF NOT EXISTS `tbApp_por_tbPais` (
  `tbApp_app_cod` INT NOT NULL,
  `tbPais_id` INT(11) NOT NULL,
  PRIMARY KEY (`tbApp_app_cod`, `tbPais_id`),
  INDEX `fk_tbApp_has_tbPais_tbPais1_idx` (`tbPais_id` ASC),
  INDEX `fk_tbApp_has_tbPais_tbApp1_idx` (`tbApp_app_cod` ASC),
  CONSTRAINT `fk_tbApp_has_tbPais_tbApp1`
    FOREIGN KEY (`tbApp_app_cod`)
    REFERENCES `tbApp` (`app_cod`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_tbApp_has_tbPais_tbPais1`
    FOREIGN KEY (`tbPais_id`)
    REFERENCES `tbPais` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

tbRevenda_has_tbApp

CREATE TABLE IF NOT EXISTS `tbRevenda_has_tbApp` (
  `tbRevenda_id` INT(11) NOT NULL,
  `tbApp_app_cod` INT NOT NULL,
  `tbApp_Qtde` VARCHAR(45) NULL,
  PRIMARY KEY (`tbRevenda_id`, `tbApp_app_cod`),
  INDEX `fk_tbRevenda_has_tbApp_tbApp1_idx` (`tbApp_app_cod` ASC),
  INDEX `fk_tbRevenda_has_tbApp_tbRevenda1_idx` (`tbRevenda_id` ASC),
  CONSTRAINT `fk_tbRevenda_has_tbApp_tbRevenda1`
    FOREIGN KEY (`tbRevenda_id`)
    REFERENCES `tbRevenda` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_tbRevenda_has_tbApp_tbApp1`
    FOREIGN KEY (`tbApp_app_cod`)
    REFERENCES `tbApp` (`app_cod`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

mvx_serial

CREATE TABLE IF NOT EXISTS `mvx_serial` (
  `mvx_cod` INT NOT NULL,
  `mvx_num_serial` VARCHAR(45) NULL,
  `tbPais_id` INT(11) NOT NULL,
  PRIMARY KEY (`mvx_cod`),
  INDEX `fk_mvx_serial_tbPais1_idx` (`tbPais_id` ASC),
  CONSTRAINT `fk_mvx_serial_tbPais1`
    FOREIGN KEY (`tbPais_id`)
    REFERENCES `tbPais` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

cambio

CREATE TABLE IF NOT EXISTS `cambio` (
  `combio_cod` INT NOT NULL,
  `cambio_valor` VARCHAR(45) NULL,
  PRIMARY KEY (`combio_cod`))
ENGINE = InnoDB;

historico

CREATE TABLE IF NOT EXISTS `historico` (
  `hist_cod` INT NOT NULL,
  `hist_geracao_dt_ativacao` VARCHAR(45) NULL,
  `hist_metodo_de_download` VARCHAR(45) NULL,
  `hist_licencas_qtde` VARCHAR(45) NULL,
  `hist_ip` VARCHAR(45) NULL,
  `hist_alias` VARCHAR(45) NULL,
  `tbApp_app_cod` INT NOT NULL,
  `cupomDesc_cupom_cod` INT NULL,
  `mvx_serial_mvx_cod` INT NOT NULL,
  `tbRevenda_id` INT(11) NOT NULL,
  PRIMARY KEY (`hist_cod`),
  INDEX `fk_historico_tbApp1_idx` (`tbApp_app_cod` ASC),
  INDEX `fk_historico_cupomDesc1_idx` (`cupomDesc_cupom_cod` ASC),
  INDEX `fk_historico_mvx_serial1_idx` (`mvx_serial_mvx_cod` ASC),
  INDEX `fk_historico_tbRevenda1_idx` (`tbRevenda_id` ASC),
  CONSTRAINT `fk_historico_tbApp1`
    FOREIGN KEY (`tbApp_app_cod`)
    REFERENCES `tbApp` (`app_cod`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_historico_cupomDesc1`
    FOREIGN KEY (`cupomDesc_cupom_cod`)
    REFERENCES `cupomDesc` (`cupom_cod`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_historico_mvx_serial1`
    FOREIGN KEY (`mvx_serial_mvx_cod`)
    REFERENCES `mvx_serial` (`mvx_cod`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_historico_tbRevenda1`
    FOREIGN KEY (`tbRevenda_id`)
    REFERENCES `tbRevenda` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;
3zwtqj6y

3zwtqj6y1#

该错误似乎存在于外键约束上

CREATE TABLE IF NOT EXISTS `tbApp_por_tbPais` (
...
CONSTRAINT `fk_tbApp_has_tbPais_tbPais1`
    FOREIGN KEY (`tbPais_id`)
    REFERENCES `tbPais` (`id`)

我没有看到名为tbPais的表。

tkclm6bt

tkclm6bt2#

作为错误信息,对于这个表tbApp_por_tbPais使用了外键ref tbPais.id,但是您没有这个表(tbPais)。

CREATE TABLE IF NOT EXISTS `tbApp_por_tbPais` (
  `tbApp_app_cod` INT NOT NULL,
  `tbPais_id` INT(11) NOT NULL,
  PRIMARY KEY (`tbApp_app_cod`, `tbPais_id`),
  INDEX `fk_tbApp_has_tbPais_tbPais1_idx` (`tbPais_id` ASC),
  INDEX `fk_tbApp_has_tbPais_tbApp1_idx` (`tbApp_app_cod` ASC),
  CONSTRAINT `fk_tbApp_has_tbPais_tbApp1`
    FOREIGN KEY (`tbApp_app_cod`)
    REFERENCES `tbApp` (`app_cod`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_tbApp_has_tbPais_tbPais1`
    FOREIGN KEY (`tbPais_id`)
    REFERENCES `tbPais` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

还丢了tabletbRevenda。

CREATE TABLE IF NOT EXISTS `tbPais` (
  `id` INT NOT NULL PRIMARY key
    )
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `tbRevenda` (
  `id` INT(11) NOT NULL PRIMARY KEY
    )
ENGINE = InnoDB;
uqzxnwby

uqzxnwby3#

尝试在表名之前键入您的数据库名...

CREATE TABLE IF NOT EXISTS `databasename.cambio` (

相关问题