1

我尝试从我的 MySQL 数据库创建一个实体类。Netbeans 中的向导给我错误消息“无法添加,因为它没有主键”。但是我的表中有一个主键。这似乎是其他人在这个论坛遇到的一个错误:

https://netbeans.org/bugzilla/show_bug.cgi?id=167389

我已经尝试了线程中的建议,但没有得到它的工作。我错过了什么?我可以强制 Netbeans 导入实体类吗?

我正在使用 NetBeans 7.3

这是我的桌子:

CREATE  TABLE IF NOT EXISTS `estelle`.`FrasVal` (
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
`Varde` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL ,
`Kommentar` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL ,
`RegistreratDatum` DATETIME NOT NULL ,
`FrasFragaSvarAlternativ_ID` INT(11) NULL ,
`Anvandare_ID` INT(11) NOT NULL ,
`Patient_ID` INT(11) NOT NULL ,
`FrasFraga_ID` INT(11) NOT NULL ,
PRIMARY KEY (`ID`) ,
UNIQUE INDEX `ID_UNIQUE` (`ID` ASC) ,
INDEX `fk_FrasVal_FrasFragaSvarAlternativ1_idx` (`FrasFragaSvarAlternativ_ID` ASC) ,
INDEX `fk_FrasVal_Anvandare1_idx` (`Anvandare_ID` ASC) ,
INDEX `fk_FrasVal_Patient1_idx` (`Patient_ID` ASC) ,
INDEX `fk_FrasVal_FrasFraga1_idx` (`FrasFraga_ID` ASC) ,
CONSTRAINT `fk_FrasVal_FrasFragaSvarAlternativ1`
FOREIGN KEY (`FrasFragaSvarAlternativ_ID` )
REFERENCES `estelle`.`FrasFragaSvarAlternativ` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_FrasVal_Anvandare1`
FOREIGN KEY (`Anvandare_ID` )
REFERENCES `estelle`.`Anvandare` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_FrasVal_Patient1`
FOREIGN KEY (`Patient_ID` )
REFERENCES `estelle`.`Patient` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_FrasVal_FrasFraga1`
FOREIGN KEY (`FrasFraga_ID` )
REFERENCES `estelle`.`FrasFraga` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci;
4

3 回答 3

2

I have tried the suggestions in the thread but have not gotten it to work.

Are you sure? The code sample you have posted don't show that. If necessary, update your question to reflect the actual state of your problem.


According to the link you provided, a possible (?) workaround would be to spell you table all lowercase:

"Something that gave me a hard time is that for some funky reason the table names must be all in lower case. If tables names are in mixed case the relationships will not be discovered during the reverse engineering process. During my experimentation I discovered that the Middlegen docs give a warning about this, so I am guessing that the Eclipse DALI plugin uses Middlegen under the covers. The MySQL engine should also be INNODB."

And https://netbeans.org/bugzilla/show_bug.cgi?id=167389#c11

The problem will happen if you have foreign keys where upper case and lower case table names don't match the referenced table's definition.


I would suggest (1) to use all lowercase table names and (2) ensure that table references are spelled the same on foreign key constraints.

CREATE  TABLE IF NOT EXISTS `estelle`.`frasval` (
--                                     ^^^^^^^
 ...

REFERENCES `estelle`.`frasfragasvaralternativ` (`ID` )
--                    ^   ^    ^   ^

You should probably be able to use underscore _ in your table name as well (definitively make things more readable!). Please post your conclusions if you have time to made some experiments!

于 2013-08-08T11:38:55.587 回答
0

当我收到错误时,我删除了外键,再次添加它们,重新启动 mysql 连接并且它工作

于 2017-10-13T09:24:39.113 回答
0

这是因为您的字段“ID”名称的第一个字符是大写。尝试使用“id”。我知道,听起来很傻,但这对我有用。

于 2019-03-05T19:17:08.197 回答