Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default value to column in ormlite?

I am new to ormlite and i want to set default value for some fields like

@DatabaseField(generatedId = true, canBeNull = false)
int id;
@DatabaseField(canBeNull = true)
String user_type;
@DatabaseField(canBeNull = true)
String username;
@DatabaseField(canBeNull = true)
String password;
@DatabaseField(canBeNull = true)
int id_color;

I have to set the default value for the username field. How do I do this? Thanks in advance!!!!

like image 525
Sourabh Saldi Avatar asked Dec 15 '22 21:12

Sourabh Saldi


1 Answers

I have to set the default value for the username field. How do I do this?

I've spent a lot of time on the ORMLite documentation. You should always start there. If you go to the documentation index, and look up default value it would show you that there is a defaultValue field in @DatabaseField annotation. Here are the javadocs for that field.

Something like the following should work:

@DatabaseField(defaultValue = "unknownName", canBeNull = true)
String username;
like image 89
Gray Avatar answered Jan 06 '23 05:01

Gray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!