Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a set column with database migration in rails

I need to add a new column to my users table in the database. I want the type of the column to be set. The column represents the users gender. There should be two options to the set. One form Male "m" and the other for Female "f".

But I haven't found any documentation for adding a column with the set type.

How can I do this?

like image 635
Lisinge Avatar asked Mar 22 '26 14:03

Lisinge


1 Answers

What db is used? mysql? If you're want to use SET datatype, you'll have to do it manually, as rails doesn't support it. However, I'd do just

t.string :gender, :limit => 1

for the sake of convenience.

like image 182
Evgeny Shadchnev Avatar answered Mar 25 '26 05:03

Evgeny Shadchnev



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!