samedi 2 juillet 2016

what should i do to make sure 'username' unique in table user and avoid duplicate entry '*' for key 2

I created two tables, user and journey. In table user, I added a column named username and made it unique. In table journey, I reference user_id (the primary key in table user) to foreign key in table journey. two tabless SQL below: create table user( user_id INT auto_increment PRIMARY KEY, username varchar(50) not null, avator varchar(50), gender boolean not null, phone varchar(20), unique(username) ); create table journey(     id INT auto_increment PRIMARY KEY,     start varchar(100) not null,     dest varchar(100) not null,     time date not null,     person INT,     user_id INT not null,     foreign key(user_id) references user(user_id) ); user and journey's relation is one-to-many When I insert new journey data into table journey, hibernate always tried to insert user info into table user, but username is set to be unique, so exception occurs. I am not familiar with databases, what should I do?

Aucun commentaire:

Enregistrer un commentaire