How To Migrate Your Development And Test Database In One Command With Rails

If you’re using test driven development in your Ruby on Rails application, chances are, migrations are kind of annoying. You always have to remember to run rake db:test:prepare right after rake db:migrate. If you happen to forget, your tests will fail and you might not realize why, adding an additional few minutes of frustration to your day.

The solution to this is pretty simple, as I learned. Rake accepts multiple arguments, so you can migrate both your development and test database in one command like this:

$ rake db:migrate db:test:prepare

If you make this your default command for all migrations, your mind will be free to think about the more important things in life 😉

Enjoy the article? Join over 20,000+ Swift developers and enthusiasts who get my weekly updates.

  • poov

    Hey Natasha,

    I’ve followed your blog for a while and it helps me a lot to stay motivated (since you are doing extremely well!) and I have a sort of similar background than you had (I did CS106A + CS106B and half of CS193p for the moment). I would like to try ruby on rails while continuing to learn iOS and I know that dev bootcamp is a great option but I have a few problems:

    – I’m a college dropout (from a top school, in the same ballpark than your alma mater, not that I care about that kind of bs), I’m afraid Dev Bootcamp or Code Fellows will look at that negatively since I can’t really explain why I dropped out

    – I don’t have the money to do Dev Bootcamp and I don’t live in the US anymore

    So I decided to follow CS142 from Stanford



    Do you think that the material covered is kinda similar to Dev Bootcamp ? Of course, nothing can replace the actual experience of studying with fellow students and teachers


    • Hi,

      Dev Bootcamp is trying to change education, so dropping out of college is probably more of a plus than a minus! The attitude is similar in the industry – if you’re good, nobody cares what school you went to. Here are two popular articles that came up the other day on the subject:

      If I knew what I know now, I probably wouldn’t have gone to college to be honest. It was a waste of time and lots of money (yes, I’m still paying off my student loans!). I was a Psychology major, and now I’m a Software Engineer. I learned how to follow instructions and do the minimum to get a good grade.

      Another big problem with college is that it’s focused way too much on theory instead of practice. I really loved Dev Bootcamp because I learned the practical skills I needed to be a Software Developer and build my own websites and products. Sure, algorithms are useful once in a while, but ultimately most of development requires very repetitive and simple tasks. When I get to the part where I need an algorithm, I’ll figure it out – or more likely, I can just use something someone else already figured out (love open source!).

      The Stanford CS142 looks pretty old, like it’s from 2010. Ruby on Rails moves very quickly, so whatever they’re teaching will be pretty outdated. I recommend trying out the Ruby on Rails tutorial: If you want more video-based content, check out and might have something. RubyLearning also has a great class on just Ruby:

      If you can get back to the U.S., there are alternatives to Dev Bootcamp. For example, only charges you if you get a job and is free. If you can save up some money, is also a good online alternative to Dev Bootcamp if you take advantage of it.

  • poov

    Thanks a lot for your answer!

    I will check out those links. Good luck with tinysale (I really like the name!)