【问题标题】:NetBeans 6.7 Beta - Why does it think certain tables have no primary key?NetBeans 6.7 Beta - 为什么它认为某些表没有主键?
【发布时间】:2010-10-24 22:11:52
【问题描述】:

我正在使用 NetBeans 6.7 Beta 从 MySQL(版本“5.0.45-log”)数据库创建实体类。 NetBeans 接受大多数表,但始终拒绝某些表(我看不到模式),称它们“没有主键”。所有表都使用 InnoDB 引擎。所有表都有一个或多个列的主键。 MySQL 查询浏览器和 NetBeans 的内部数据库导航器都同意所有表实际上都有一个主键。怎么了?

这里是生成坏表的脚本 sn-p:

-- -----------------------------------------------------
-- Table `beamline`.`rq_requests`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `beamline`.`rq_requests` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `facility_id` INT NOT NULL ,
  `schedule_id` INT NOT NULL ,
  `experiment_id` INT NOT NULL ,
  `person_id` INT NOT NULL ,
  `shift_per_block` INT NOT NULL ,
  `block_count` INT NOT NULL ,
  `other_requirment` VARCHAR(1023) NULL ,
  `submitted` BOOLEAN NOT NULL ,
  `date_modified` DATETIME NOT NULL ,
  `date_created` DATETIME NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_rq_requests_xa_facilities` (`facility_id` ASC) ,
  INDEX `fk_rq_requests_xa_schedules` (`schedule_id` ASC) ,
  INDEX `fk_rq_requests_eec_exp_toc` (`experiment_id` ASC)
# ,INDEX `fk_rq_requests_eec_members` (`person_id` ASC)
 ,CONSTRAINT `fk_rq_requests_xa_facilities`
    FOREIGN KEY (`facility_id` )
    REFERENCES `beamline`.`xa_facilities` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION
 ,CONSTRAINT `fk_rq_requests_xa_schedules`
    FOREIGN KEY (`schedule_id` )
    REFERENCES `beamline`.`xa_schedules` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION
 ,CONSTRAINT `fk_rq_requests_eec_exp_toc`
    FOREIGN KEY (`experiment_id` )
    REFERENCES `beamline`.`eec_exp_toc` (`exp_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION
# ,CONSTRAINT `fk_rq_requests_eec_members`
#    FOREIGN KEY (`person_id` )
#    REFERENCES `beamline`.`rq_questions` (`admin_uid` )
#    ON DELETE NO ACTION
#   ON UPDATE NO ACTION
)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `beamline`.`rq_questions_facilities`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `beamline`.`rq_questions_facilities` (
  `facility_id` INT NOT NULL ,
  `question_id` INT NOT NULL ,
  PRIMARY KEY (`facility_id`, `question_id`) ,
  INDEX `fk_req_faciliy_current_question_req_question` (`question_id` ASC) ,
  INDEX `fk_rq_questions_facilities_xa_facilities` (`facility_id` ASC),
  CONSTRAINT `fk_req_faciliy_current_question_req_question`
    FOREIGN KEY (`question_id` )
    REFERENCES `beamline`.`rq_questions` (`id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_rq_questions_facilities_xa_facilities`
    FOREIGN KEY (`facility_id` )
    REFERENCES `beamline`.`xa_facilities` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION
 )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `beamline`.`rq_questions_supressed`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `beamline`.`rq_questions_suppressed` (
  `facility_id` INT NOT NULL ,
  `question_id` INT NOT NULL ,
  PRIMARY KEY (`facility_id`, `question_id`) ,
  INDEX `fk_req_facility_suppressed_question_req_question` (`question_id` ASC) ,
  INDEX `fk_rq_questions_suppressed_xa_facilities` (`facility_id` ASC),
  CONSTRAINT `fk_req_facility_suppressed_question_req_question`
    FOREIGN KEY (`question_id` )
    REFERENCES `beamline`.`rq_questions` (`id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_rq_questions_suppressed_xa_facilities`
    FOREIGN KEY (`facility_id` )
    REFERENCES `beamline`.`xa_facilities` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

什么给了?提前致谢。

【问题讨论】:

  • 这不应该是 NetBeans 错误报告吗?

标签: mysql netbeans jpa primary-key entity


【解决方案1】:

问题解决了; xa_facilities 的外键是 INT(11),而 xa_facilities 的主键是 INT(4)。呵呵!

【讨论】:

    【解决方案2】:

    我已尝试运行您的查询 (NB6.5.1),但它们似乎工作正常。我确实必须注释掉所有的外键约束,所以这不是一个精确的复制。

    鉴于此,您是否有可能没有创建所有引用的表(xa_facilities、rq_questions 等)?它们的结构是否正确?

    我建议将来将关系约束分离到单独的脚本中,这样您就可以始终确定在所有表都存在之后创建它们。

    【讨论】:

      猜你喜欢
      • 2017-06-25
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 1970-01-01
      • 2021-12-23
      • 2012-02-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多