Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify a Specific Migration

I have migration (created way back) that i need to change, it's the below:

20130923000732_create_questions.rb

I need to change

 t.string to --> t.text

how can i achieve this ?

I read along that i can create a new migration renaming the column, but i did not quite understand it.

like image 911
Mini John Avatar asked Dec 01 '22 03:12

Mini John


2 Answers

If 20130923000732_create_questions.rb migration is your last migration you can rollback with:

rake db:rollback

Otherwise you can simply down your specific migration with VERSION:

rake db:migrate:down VERSION=20130923000732

After rollback your migration, change your migration file and migrate again.

like image 71
xaph Avatar answered Dec 04 '22 04:12

xaph


Your app is in development yet, just open that migration in edtor, change it to text and run all your migrations again. Or write a migration that will update that field type.

First in you terminal:

rails g migration change_column_type_in_questions

Then in your migration file:

class ChangeColumnTypeInQuestions < ActiveRecord::Migration
  def change
    change_column :questions, :body, :text
  end
end

Migration will look for table questions and will update column body type without loosing data.

like image 43
rmagnum2002 Avatar answered Dec 04 '22 03:12

rmagnum2002