Add boolean column with default to existing table

I wanted to add a boolean field approved with the default value false to an existing model Users in a Rails project.

Create the migration file by using rails generate:

Your file will look like this

Now add default: 0 that it looks like this

Side note

In forms you can make use of the check_box function to display and manipulate the boolean value

(50 Posts)

20 years of coding and working as software engineer but I am still eager to learn more. I am very passionate when it comes to open source, Linux and Java. But I made my peace with Windows long ago to fully enjoy my PC gaming hobby. I have a soft spot for 90s electronic music and Babylon 5. In the evenings you will find me roaming the endless space in Warframe (IGN k05h).

2 thoughts on “Add boolean column with default to existing table

Comments are closed.