2016-12-02 44 views
-1

我有一个用户表相关联的,它有一个工会重点open_id,现在我想建立一个表 ,它需要与工会相关的主键键。顺便说一句,我使用mysql5.6和open_id是varchar。 对不起,我不是英语很好的......如何建立forign键作为主键,并与工会重点

CREATE TABLE click ( 
open_id varchar(11) NOT NULL, 
click_count int(11) NOT NULL DEFAULT '0', 
PRIMARY KEY (open_id), 
CONSTRAINT click_ibfk_1 FOREIGN KEY (open_id) REFERENCES user_info (u_openid) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
+0

和open_id不是主键。 – nick

+2

如果你英语不太好(我也是),请给出代码。守则是国际性的。 –

+0

CREATE TABLE'click'( 'open_id' VARCHAR(11)NOT NULL, 'click_count' INT(11)NOT NULL DEFAULT '0', PRIMARY KEY('open_id') 约束'click_ibfk_1'外键( 'open_id')REFERENCES'user_info'('u_openid') )ENGINE = InnoDB DEFAULT CHARSET = utf8;这就是我想要的 – nick

回答

0

@Entity 公共类圆{

@Id @GeneratedValue 
private int id; 

@OneToMany(mappedBy = "circle") @JsonIgnore 
private List<Enterprise> enterprises; 

@OneToMany(mappedBy = "circle") 
private List<Authority> authorities; 

@Column(nullable = false, length = 50, columnDefinition = "varchar(50) default ''") 
private String name; 

public int getId() { 
    return id; 
} 

public void setId(int id) { 
    this.id = id; 
} 

public String getName() { 
    return name; 
} 

public void setName(String name) { 
    this.name = name; 
} 

public List<Authority> getAuthorities() { 
    return authorities; 
} 

public void setAuthorities(List<Authority> authorities) { 
    this.authorities = authorities; 
} 

public List<Enterprise> getEnterprises() { 
    return enterprises; 
} 

public void setEnterprises(List<Enterprise> enterprises) { 
    this.enterprises = enterprises; 
} 

public Circle() { 
} 

public Circle(int id) { 
    this.id = id; 
} 

public Circle(String name) { 
    this.name = name; 
} 

}

@Entity 公共类企业{

@Id @GeneratedValue 
private int id; 

@ManyToOne 
private Circle circle; 

@OneToMany(mappedBy = "enterprise", cascade = CascadeType.ALL) 
private List<Creator> creators; 

@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50) 
private String name; 

@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50) 
private String createTime; 

@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50) 
private String category; 

@Column(columnDefinition = "text") @Size(max = 500) 
private String description; 

/** 
* 联系人 
*/ 
@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50) 
private String contacter; 

/** 
* 联系方式 
*/ 
@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50) 
private String contact; 

/** 
* 成员规模 
*/ 
@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50) 
private String staffSize; 

/** 
* 现阶段需求 
*/ 
@Column(columnDefinition = "text") @Size(max = 500) 
private String demand; 

/** 
* 公司性质 
*/ 
@Column(columnDefinition = "text") @Size(max = 500) 
private String nature; 

/** 
* 业务范围 
*/ 
@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50) 
private String scope; 

@Column(columnDefinition = "text") 
private String img1 = ""; 

@Column(columnDefinition = "text") 
private String img2 = ""; 

@Column(columnDefinition = "text") 
private String img3 = ""; 

@Column(columnDefinition = "text") 
private String img4 = ""; 

@Column(columnDefinition = "text") 
private String img5 = ""; 

public String getImg1() { 
    return img1; 
} 

public void setImg1(String img1) { 
    this.img1 = img1; 
} 

public String getImg2() { 
    return img2; 
} 

public void setImg2(String img2) { 
    this.img2 = img2; 
} 

public String getImg3() { 
    return img3; 
} 

public void setImg3(String img3) { 
    this.img3 = img3; 
} 

public String getImg4() { 
    return img4; 
} 

public void setImg4(String img4) { 
    this.img4 = img4; 
} 

public String getImg5() { 
    return img5; 
} 

public void setImg5(String img5) { 
    this.img5 = img5; 
} 

public String getName() { 
    return name; 
} 

public void setName(String name) { 
    this.name = name; 
} 

public String getCreateTime() { 
    return createTime; 
} 

public void setCreateTime(String createTime) { 
    this.createTime = createTime; 
} 

public String getCategory() { 
    return category; 
} 

public void setCategory(String category) { 
    this.category = category; 
} 

public String getDescription() { 
    return description; 
} 

public void setDescription(String description) { 
    this.description = description; 
} 

public String getContacter() { 
    return contacter; 
} 

public void setContacter(String contacter) { 
    this.contacter = contacter; 
} 

public String getContact() { 
    return contact; 
} 

public void setContact(String contact) { 
    this.contact = contact; 
} 

public String getStaffSize() { 
    return staffSize; 
} 

public void setStaffSize(String staffSize) { 
    this.staffSize = staffSize; 
} 

public String getDemand() { 
    return demand; 
} 

public void setDemand(String demand) { 
    this.demand = demand; 
} 

public String getNature() { 
    return nature; 
} 

public void setNature(String nature) { 
    this.nature = nature; 
} 

public String getScope() { 
    return scope; 
} 

public void setScope(String scope) { 
    this.scope = scope; 
} 

public int getId() { 
    return id; 
} 

public void setId(int id) { 
    this.id = id; 
} 

public List<Creator> getCreators() { 
    return creators; 
} 

public void setCreators(List<Creator> creators) { 
    this.creators = creators; 
} 

public Circle getCircle() { 
    return circle; 
} 

public void setCircle(Circle circle) { 
    this.circle = circle; 
} 

}