rails (4) generate migration behaviors I forget to usePosted: August 11, 2014 | Author: ThomasPowell | Filed under: daily learning | Tags: generators, migrations, rails | Leave a comment »
When I’m generating a migration, I usually don’t go any deeper than specifying column_name:data_type on the command line, and often I only use the command line to generate the file itself.
I don’t know that the other options really save all that much typing, but stopping to think about the other options for a few seconds might just help avoid having to go back later and add things.
Elementary things I don’t make enough use of:
rails g migration AddXXXtoYYYautomatically creates an add_column for table YYY for every column name specified.
rails g migration RemoveXXXtoYYYautomatically creates a remove_column for table YYY for every column name specified.
column_name:data_type:indexalso adds an index to the new column.
rails g migration CreateJoinTableXXXYYYwill produce a join table.