I am a student currently doing the program, and I've been developing things for months until now. This article is for helping newcomers to Rails to understand Rails migrations by showing some examples and explaining them the best I can. full-stack developer Microverse If you are a newbie with Rails, you may have thought that migrations are complicated, as always, it can be, but most of the time is not. First of all, let's demystify the concept of , this is just a regular file, that's right, a plain simple placed under db/migrate used by Rails to change the database schema incrementally. migration ruby file What means that changes are made incrementally? Putting it simple, something like creating a table could be one migration (remember, a file), then, other thing like renaming, adding, or indexing a column afterwards could be another migration, is not that complicated right? So, how do you create a migration? Rails expects that migrations be named in the following way: YYYYMMDDHHMMSS_my_migration.rb, obviously we don't want to write the UTC timestamp every time we create a migration, Rails have us covered, just type this in your terminal (obviously you must be in the Rails application directory). rails generate migration CreateProducts title:string description:text price:decimal image_url:string What's that gibberish? That's how you'll usually a migration, this specific migration defines the creation of a table named products, with columns: title of type string, description of type text, price of type decimal that has a precision of 8 significant figures and 2 digits after the point, and image_url of type string. generate Alright then, is that all? Well, if you wanted to add something extra you can go and edit the migration, let's take a look at the generated file, remember that it should be called something like 20191205104706_create_products.rb and be placed under the directory of your Rails application. db/migrate create_table t.title t.description t.price , , t.image_url t.references , t.timestamps < ActiveRecord::Migration[6.0] class CreateProducts def change :products do |t| :string :text :decimal precision: 8 scale: 2 :string # I forgot about suppliers :supplier foreign_key: true # This only creates columns created_at and updated_at, is a default end end end Now, let's see the current state of our migrations. rails db:migrate:status You should see something like the following (this is the migrations status of one of my rails experiments). If you haven't applied the migrations yet (more on that in a moment), some migrations should have a status of , to apply pending migrations run the task. down db:migrate rails db:migrate Now, if you take a look at the status of your migrations all of them should be . up A good feature about migrations is the ability of going back in time, this is achieved by the task. db:rollback rails db:rollback This will revert the latest migration, of course, you can revert several migrations at once. rails db:rollback STEP=3 This will revert the last 3 migrations. Normally, you'll want to do little things like adding a column to an existing table. rails generate migration add_sales_to_products sales:bigint add_column , , < ActiveRecord::Migration[6.0] class AddSalesToProduct def change :products :sales :bigint end end And sometimes, you want to do several changes to an existing table. rails generate migration change_products change_table t.remove , t.index < ActiveRecord::Migration[6.0] class ChangeProducts def change :products do |t| :image_url :description :title end end end There are a lot of more complicated things you can do with migrations, but for a beginner this will do for now. If you want to know more about migrations, the guys that work on Rails provide a lot of useful . But never forget. information on the subject The only way of learning some activity is by actually performing such activity over and over until it becomes natural to you. Hope this article helped a bit to your grasp of Rails migrations, you can reach me out in , , , and . LinkedIn Github Twitter Facebook