异常信息
Error executing DDL "alter table blog_comment add constraint FK5pu6xb8447el9dfjw4ftmpk0i foreign key (articleId) references blog_article (articleId)" via JDBC Statement
实体类
package com.blog.entity;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/*
* 文章评论
*/
@Entity
@Table(name="blog_comment")
public class Comment {
private Long commentid;
private Article article;//文章
private Date createTime;//评论时间
private User user;//评论者
private String content;//评论内容
private Comment target;//针对的目标
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getCommentid() {
return commentid;
}
@ManyToOne
@JoinColumn(name="articleId")
public Article getArticle() {
return article;
}
@ManyToOne
@JoinColumn(name="userId")
public User getUser() {
return user;
}
@ManyToOne
@JoinColumn(name="targetId")
public Comment getTarget() {
return target;
}
public void setCommentid(Long commentid) {
this.commentid = commentid;
}
public void setArticle(Article article) {
this.article = article;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public void setUser(User user) {
this.user = user;
}
@Column(columnDefinition="TEXT")
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public void setTarget(Comment target) {
this.target = target;
}
}
Springboot 建了个实体,其中两个字段是关联外键,User和Article现在提示创建失败。什么原因呢?
Article实体也有关联的外键,相同的方法就创建成功了。。