#1005 - 无法创建表格

时间:2013-09-17 14:13:30

标签: mysql

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

2 个答案:

答案 0 :(得分:0)

错误似乎是外键约束

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

我没有看到名为tbPais的表格。

答案 1 :(得分:-1)

尝试在表名...

之前输入您的数据库名称
CREATE TABLE IF NOT EXISTS `databasename.cambio` (