1
我一直在尝试使用MYSQL添加约束UNSIGNED到列。下面是我的桌子。在休眠INT(11)UNSIGNED约束
public class UserActivity implements BaseEntity{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
Long entityId;
@Column(columnDefinition = "enum('QUESTION','ANSWER', 'COMMENT', 'TAGS')")
@Enumerated(EnumType.STRING)
Type type;
@ManyToOne
@JoinColumn(nullable = false, columnDefinition="INT(11) UNSIGNED")
CustomerEntity user;
但它不创造因的外键和索引没有建立数据库约束用户列。 This和this忍不住。请帮助我。感谢
原木:
Hibernate:
alter table UserActivity
add constraint FK_jfw954ii6gw7mbqdth6y3n0rs
foreign key (user_Id)
references customerDb.customer (Id)
12:31:30.350 [localhost-startStop-1] ERROR o.h.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: alter table UserActivity add constraint FK_jfw954ii6gw7mbqdth6y3n0rs foreign key (user_Id) references customerDb.customer (Id)
12:31:30.350 [localhost-startStop-1] ERROR o.h.tool.hbm2ddl.SchemaExport - Can't create table 'community_db.#sql-43f0_5a07' (errno: 150)
Hibernate:
MySQL的查询:
ALTER TABLE `community_db`.`Question`
ADD INDEX `fk_Question_Customer_idx` (`author_Id` ASC);
ALTER TABLE `community_db`.`Question`
ADD CONSTRAINT `fk_Answer_Customer`
FOREIGN KEY (`author_Id`)
REFERENCES `customerDb`.`customer` (`Id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
和下面是上述MySQL的查询日志:
Error Code: 1005. Can't create table 'community_db.#sql-43f0_5d19' (errno: 150) 0.048 sec
你能发布你得到的实际错误吗? –
在我搜索'UNSIGNED'的日志中找不到。没有查询UNSIGNED和show_sql和format_sql为真 –
@TimBiegeleisen我已经添加了来自日志的查询 –