I have ran my migrations on my production server and I am using MySQL, I get this error:
Mysql2::Error: Invalid default value for 'admin': ALTER TABLE
users
ADDadmin
tinyint(1) DEFAULT 'false'`
my migration looks like this:
class AddAdminToUsers < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean, default: :false
end
end
I understand the error is because "false" is not a proper value for a tinyint, this should be a 0 in this case. I thought default: :false was the right way to default a boolean to false.
How do I fix this so MySQL does not complain about the bad value?
false
is not a symbol I believe. Try this
add_column :users, :admin, :boolean, default: false
PS
I am wrong. So you should set default: 0
:(. Or you can patch ActiveRecord::Migration
so it will accept true|false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With