A common change that you will make to Rails projects is you start with a model having an attribute of one type and then you realise it needs to be another.
This might be something like thinking you should store an integer when it should actually be a string. New developers often think phone numbers should be stored as integers because they are numbers, but forget that integers can’t start with zero (and most phone numbers start with zero).
To kick things off we need to generate a new migration
What you call this migration will have no impact on what we need to do next, but future you and other developers will thank you for naming your migration appropriately.
If you open up the migration you should see something like this
As you can see the
change method is sitting empty. We need to manually add
some code here.
The code we need to add takes the form of
In our case it would be something like
The completed file will look like this
Once you’ve saved the file you should be able to do a quick
and your database will update.