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 trialAlex Cevallos
16,551 PointsWhat is bin/rake DB:Migrate ?
Hey everyone
I was wondering what DB:Migrate was. I understand it is "migrating the database" but I was wondering what it exactly was?
Thanks in advance, I appreciate the help :)
2 Answers
Joshua Shroy
9,943 PointsLike Andrew mentioned, rake db:migrate generates a migration file. In the file, Rails creates a class that inherits from ActiveRecord:: Migration. In other words, this is Rails way of telling the database what to do. The class will have generated methods specified by what you command. For example, if you want to drop a specific table in the database, Rails will automatically create the class and methods needed to drop that table in the database.
If you check inside your rails app directory db/migrate,
you will see you the generated files named with a prefix of what looks like random numbers and along with your command. (ex. 20141019001737_create_tests.rb). These numbers represent a timestamp. The database saves the latest timestamp to a table. So when you create a migration, it runs all of the previous migrations associated with the latest timestamp, then updates the database table with your newly generated timestamp.
Hope that helps!
Andrew Stelmach
12,583 PointsI think when you run 'generate', that creates a migration file. When you run migrate it actually CREATES the new section in your database, using that migration file.