Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails migration: is it ok to use 'nil' as the default value for a boolean field?

Is there anything wrong with defaulting a boolean field to nil rather than false with an ActiveRecord migration for use with Postgres?

I like how it gives a small bit of extra data- whether or not that field has been marked as true or false yet.

like image 370
bevanb Avatar asked Aug 14 '12 03:08

bevanb


1 Answers

there is nothing to stop you from using nil on boolean - but I personally like my booleans to be true or false, i've found that having nil can lead to some ugly code

like image 166
house9 Avatar answered Oct 01 '22 17:10

house9