开发者

Rails 3.1: Problem saving record with not-null boolean mysql column (false saves as NULL)

Using Rails 3.1rc5 and devise 1.4.2. I have the following column on the users table

add_column :users, :has_d开发者_JAVA百科ummy_password, :boolean, :default => false, :null => false

Without the :null => false clause if I do the following with an existing user record...

user.has_dummy_password = false
user.save

... then then in mysql the column has a value of NULL.

With the :null => false clause I (not surprisingly) get the following mysql error:

Column 'has_dummy_password' cannot be null

I can get around this by doing

user.has_dummy_password = 0
user.save

because "under the hood" booleans are implemented as tinyint in mysql. That seems a bit unfortunate though.

Is it possible to actually set boolean column values with true/false in Rails 3.1 instead of 1/0?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜