This the existing table in migration folder.
class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.string :title
t.text :text
t.timestamps null: false
end
end
end
Now I have to add column or a new field "Picture" to the table Articles.
so, i have to create migration by using this command in the terminal.
$ rails generate migration AddPictureToArticle picture:binary
Here, we are generating migration "Add" creates "change" method in Migration, and "ToArticle" indicates the table "articles."
So, I got a migration file, db/migrate/20160112054236_add_picture_to_article.rb whose contents is:
class AddPictureToArticle < ActiveRecord::Migration
def change
add_column :articles, :picture, :binary
end
end
Now all we have to do is:
$ rake db:migrate
0 Comment(s)