0

我正在尝试在我的数据库中创建一些表,但我的 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;
4

2 回答 2

0

错误似乎在外键约束上

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

我没有看到名为tbPais.

于 2013-09-17T14:22:24.850 回答
-1

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

CREATE TABLE IF NOT EXISTS `databasename.cambio` (
于 2013-09-17T14:21:12.803 回答