How can I insert a null value in foreign key field using MySql database
I have the following data model and environment is, Hibernate 3.0(with annotations) and MySQL 5.5
DB Model:
Create table ROLE(
role_id bigint(10) auto_increment,
primary key(role_id)
);
Create table user(
userId bigint(10) not null auto_increment,
role_id bigint(10) null,
Primary key(userid),
Constraint fk1 foreign key(role_id) references ROLE(role_id)
);
I am trying to insert a USER record in database and leaving the role field empty though my role field references ROLE.ROLE_ID. While creating the User I will not have Role information. I am using Hibernate 3.0 with annotations and it is throwing error when I leave USER.ROLE_ID field empty.
Is there a way to leave foreign key blank/insert null values in it?
I have the following data model and environment is, Hibernate 3.0(with annotations) and MySQL 5.5
DB Model:
Create table ROLE(
role_id bigint(10) auto_increment,
primary key(role_id)
);
Create table user(
userId bigint(10) not null auto_increment,
role_id bigint(10) null,
Primary key(userid),
Constraint fk1 foreign key(role_id) references ROLE(role_id)
);
I am trying to insert a USER record in database and leaving the role field empty though my role field references ROLE.ROLE_ID. While creating the User I will not have Role information. I am using Hibernate 3.0 with annotations and it is throwing error when I leave USER.ROLE_ID field empty.
Is there a way to leave foreign key blank/insert null values in it?