title: Why is 'rake db:rollback' rolling back 2 steps instead of the default of 1
body: <p>I am having some problems with <code>rake db:rollback</code>. Here's the setup:</p>
  
  <p>One week ago I pulled some changes from the repository, which included a new migration. I ran <code>rake db:migrate</code> and all was well with the world. Fast-forward 7 days (and multiple commits and pushes), and I started working on a new feature. I created a new feature branch and then created a new migration. I ran that migration, wrote some codes, then realized I had made a small error in the migration that I had just created. I thought I could just run <code>rake db:rollback</code>, make a few changes to that one migration, and then <code>rake db:migrate</code> again.</p>
  
  <p>But here's the rub. When I ran <code>rake db:rollback</code> it rolled back <strong>two</strong> migrations instead of just one. Running <code>rake db:migrate</code> then migrates both of those migrations. I can go back and forth all day long, but every time it always rolls back 2 migrations.</p>
  
  <p>I did some searching around here on stackoverflow and found <a href="https://stackoverflow.com/questions/19805637/why-does-rake-dbrollback-rollback-three-steps">this question</a> that is specifically referencing the STEP parameter that can be added to <code>migrate</code> and <code>rollback</code>, but going through everything in that question has not helped me. At first nothing was returned when I ran <code>echo $STEP</code>, so I specifically set it with <code>export STEP=1</code>, but that didn't help: <code>rake db:rollback</code> still rolls back 2 steps every time. And, even when I run <code>rake db:rollback STEP=1</code> it still rolls back 2 steps.</p>
  
  <p>Also, I checked the version number in the schema, and just after running <code>rake db:migrate</code> the version is consistent with the newest migration that I just created. After running <code>rake db:rollback</code> and it going back 2 steps, the version number is consistent with the 2nd most recent migration.</p>
  
  <p>I want to solve this problem for 2 reasons:</p>
  
  <ol>
  <li>I need to rollback only <strong>one</strong> migration so I can commit my changes and then switch back to the development branch and not pollute the developement schema.</li>
  <li>I want to fully understand how <code>rake db:rollback</code> works. Maybe there is a way to hack this out and get things going, but I want to understand this at a deeper level.</li>
  </ol>
  
  <p>Is there some sort of app config that determines this? Have some wires gotten crossed and I need to manually reset something? Thanks for your help!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>As per some comments and responses:</p>
  
  <p>I explicitly set <code>export STEP=1</code> in my .bash_profile and that hasn't made a difference and it still rolls back 2 steps.</p>
  
  <p>I was aware of migrating to a specific version, and yes, that is a way to get to specific place for me. I can rollback the 2 steps that it is forcing me and then migrate forward 1 step by specifying the version. It works, but it's not how this <strong>should</strong> work and I really want to get to the bottom of all this.</p>
  
  <p>The output of <code>rake db:migrate:status</code> always returns this error:</p>
  
  <pre><code>rake aborted!
  ArgumentError: invalid value for Integer(): ""
  /Users/eliduke/.rvm/gems/ruby-2.1.0/gems/activerecord-4.0.5/lib/active_record/railties/databases.rake:98:in `%'
  /Users/eliduke/.rvm/gems/ruby-2.1.0/gems/activerecord-4.0.5/lib/active_record/railties/databases.rake:98:in `block (4 levels) in &lt;top (required)&gt;'
  /Users/eliduke/.rvm/gems/ruby-2.1.0/gems/activerecord-4.0.5/lib/active_record/railties/databases.rake:98:in `map!'
  /Users/eliduke/.rvm/gems/ruby-2.1.0/gems/activerecord-4.0.5/lib/active_record/railties/databases.rake:98:in `block (3 levels) in &lt;top (required)&gt;'
  /Users/eliduke/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `eval'
  /Users/eliduke/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `&lt;main&gt;'
  Tasks: TOP =&gt; db:migrate:status
  </code></pre>
  
  <p>And the output of <code>rake db:version</code> might be acting strange. If I have just recently migrated all the way forward, it is <code>20150309194758</code>, which corresponds to my most recent migration. If I have just rolled back (the 2 steps it is forcing me), the version is <code>20150203171351</code>, which corresponds to the migration that is <strong>3</strong> steps back. Is that normal? Shouldn't it be <code>20150303192838</code>, which is 2 steps back?</p>
  
  <p>Also, I now see a peculiarity in the output for <code>rake db:rollback</code>. It first shows the rolling back of the first migration like normal (1 step) and then it looks like maybe the Apartment gem is chiming in and rolling back the next migration (2 step).</p>
  
  <pre><code>== 20150309194758 CreateFeeds: reverting ======================================
  -- drop_table(:feeds, {:id=&gt;false})
     -&gt; 0.0291s
  == 20150309194758 CreateFeeds: reverted (0.0293s) =============================
  
  Rolling back development tenant
  == 20150303192838 AddDisplayRankToEventPrizes: reverting ======================
  -- remove_column(:event_prizes, :display_rank, :integer, {:index=&gt;true, :after=&gt;:winner_user_id})
     -&gt; 0.5963s
  == 20150303192838 AddDisplayRankToEventPrizes: reverted (0.5964s) =============
  </code></pre>
  
  <p>See that <code>Rolling back development tenant</code> line? Could the apartment gem be causing the 2nd step rollback?</p>