I think the crucial piece of information that you are missing is this: there is some magic going on with the command you use from the terminal, `rake generate migration add_something_to_something_else`. That command does several things;
1) Creates a migration file
2) Makes sure the migration file has a timestamp in the filename
3) Makes sure the filename matches the name of the class that's defined inside of it (all migrations are really just Ruby classes with either a) both an `up` and a `down` method, or b) a single `change` method).
Additionally, it can do some magic stuff based on the name of the migration or params you pass when you run the command, like:
4) Create either the `change` method or the `up` and `down` methods.
5) Add the code that actually does the migration (eg. `change_column :table_name, :column_name, :new_type`)
The problem you're running into is that you have been following tutorials/examples that are taking advantage of the magic stuff and now the magic isn't working, so you're confused. If you've seen The Wizard of Oz, it's time to pay attention to the man behind the curtain (
http://www.youtube.com/watch?v=NZR64EF3OpA)
The command you use in your terminal is the **least important** part of creating a migration for your Rails app. It's main purpose is to simply create a migration file whose filename starts with a timestamps (so Rails knows which order to run the migrations in) and also contains the name of the migration class contained in the file. So, your migration file might be named something like: `20141028090567_add_email_to_contacts.rb`. The numbers are the timestamp, in this case October 28, 2014 09:05:67. The rest is a snake cased version of the class defined inside the migration file, `AddEmailToContacts`, which is in camel case (same as the scheme for naming the files that contain your models and controllers).
THE IMPORTANT PART OF THE MIGRATION IS WHAT HAPPENS INSIDE THE CLASS DEFINED IN THE MIGRATION FILE (sorry for yelling, but that's the key). The reason why your migrations are not doing anything is because they are empty. You are running your migrations with `rake db:migrate`, but nothing changes in your database because nothing is defined inside your migration class.
There are two methods that you put inside of a migration class, `up` and `down`. `up` specifies what should happen when you run the migration with `rake db:migrate` and `down` specifies what should happen when you reverse the migration with `rake db:rollback`. So, in the case of adding an email field to the contacts table, your migration would look like this:
def AddEmailToContacts < ActiveRecord::Migration
def up
add_column :contacts, :email, :text
end
def down
remove_column :contacts, :email
end
end
Now, in this case, we have a pretty simple transformation and, crucially, defining separate up and down methods is redundant. Rails is smart (or crazy magical, take your pick) and knows that the opposite of adding a column is removing a column. So, it's redundant to specify that we want to do `add_column :contacts, :email, :text` in the `up` method and then also specify that we want to do `remove_column :contacts, :email` in the `down` method. In Rails, this is called a reversible migration (
http://api.rubyonrails.org/classes/ActiveRecord/Migration.html#class-ActiveRecord::Migration-label-Reversible+Migrations).
Rails knows what needs to happen to undo the effects of `add_column`. If the only transformations inside of your migration are reversible ones, you can use a single `change` method, instead of both the `up` and the `down` method. So, we could rewrite our migration from above like this:
def AddEmailToContacts < ActiveRecord::Migration
def change
add_column :contacts, :email, :text
end
end
So, what you need to do from here (if I am not mistaken), is do `rake db:rollback` enough times to undo your blank migration (pay attention to the output to tell when you have reversed the migration in question). Then, put some transformations inside your migration and do `rake db:migrate` again.
Hope that helps,
Rico