1

So assume I have used rails generate to create a model and subsequently it created migrations for it.

Now it turns out I made a couple of modifications to those models (fixed up some relations). Is it possible to create migrations based off of my current model?

  • I don't want to use rails generate to generate the model again.
  • I don't want to manually write a migration.

1 Answer 1

1

What do you need to do with that migration?

If you need to remove or add some columns, you could use: AddXXXToYYY and RemoveXXXFromYYY.

So if you want to add a certain column to YYY table use:

rails generate migration add_attr1_and_attr2_to dogs attr1:string attr2:string

This would generate (rails 3.2.0):

class AddAttr1AndAttr2ToDogs < ActiveRecord::Migration
  def change
    add_column :dogs, :attr1, :string

    add_column :dogs, :attr2, :string

  end
end

Same goes for removing the columns:

r g migration remove_attr1_and_attr2_from_dogs attr1:string attr2:string

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.