今天用Hibernate建立外键的时候发现没有建立 但是创建了这个字段 情景: user表有一字段role,role是role表id字段的外键
原因: user表中已经有记录了,而且有的记录role这个字段在role表没有对应的id,所以就不能创建外键
解决方案: 先手动修改user.role字段,修改成已经在role表中存在的id值