懂得多不容易犯错----hibernatre 一对一外键关联的时候给表添加外键报错

刚接触one-to-one,需要创建B表的主键name是由A表的外键name引用过来的

创建好了表,但是添加外键一直失败!

经过查略资料,上网,发现问题时处在外键的创建上,mysql创建外键对应关系列必须创建了索引

create table people(
id int primary key auto_increment,
name varchar(100) not null,
sex varchar(100) not null,
age int
)

create table peopleName(
name varchar(100) primary key,
usetime int 
)
create index pe_name on people(name)


alter table peopleName add constraint FK_Reference_4 foreign key (name)
      references people (name);

 

posted @ 2016-04-20 18:47  guodaxia  阅读(118)  评论(0编辑  收藏  举报