Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby on Rails 5 Basics Adding a Model Attribute Updating the Model

Karrtik Iyer
Karrtik Iyer
3,738 Points

Does name of the migration need to follow a convention?

In the below example: rails generate migration AddBodyToPosts body:text

How does Rails know that model in question is Post? What if there were multiple models? Does it recognise the model name by the name of the migration, which would mean that even name of migration needs to follow a convention? If so can you please explain all conventions for migration (new column, update column, drop column, etc.).

1 Answer

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

It doesn't have to; in the end all that matters is the methods called in the migration file. But Rails will automatically generate some of those method calls for you if the name of the migration you're generating follows certain conventions. Those conventions are listed under the documentation subsection at this link.