MySql: DEFAULT does NOT prevent NULL

I just came across a serious bug/gotcha when using mysql.
Integer, default 0 -> set to NULL –> NULL and not 0

always set NOT_NULL and DEFAULT!


change_column :order_items, :shipping, :boolean, :default=>false

#shipping is nil or false or true
OrderItem.find(:all,:conditions=>{:shipping=>false}) => [] 

change_column :order_items, :shipping, :boolean, :default=>false, :null=>false

OrderItem.find(:all,:conditions=>{:shipping=>false}) => [all]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s