× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Introduction to Rails database migrations

Milos Blasko
Aug 12, 2014
<p><strong>Q: What was the request about? </strong><br>I would like to learn how Rails migrations work.<br><br><strong>Q: How did you help with the request?</strong><br>I explained the fundamentals and went through several examples inside Keeya's own project<br><br><strong>Q: Any best practices &amp; key learnings you can share?</strong></p><p>If you need to put any ActiveRecord commands inside your migration, for example</p><pre><code class="language-ruby">add_column :users, :status, :string User.update_all("status = 'single'")</code></pre><p>don't use def change but</p><pre><code class="language-ruby">def up add_column :users, :status, :string User.update_all("status = 'single'") end def down remove_column :users, :status end</code></pre><p>Otherwise your migration would cracsh during rake db:rollback.</p>