I generated a rails 3.2 migration with an empty down function, because the migration is irreversible (and I don’t want to throw an exception). I run the migration successfully, but it has no effect. When I rollback, and run db:migrate again, the effects does apply.
I solved this easily by filling the empty down function with a code which does nothing, but it’s still pretty ugly.
Does anyone knows why this happens? Is this a rails bug?
The exception is throwed to prevent destroying your database, if its irreversable, then that’s probably the right thing to do.
Your
#downcould look like this:That will save others a lot of headache as it clearly notifies about irreversable migration and explains the reason behind it 🙂
EDIT: I cannot confirm this behaviour for Rails 3.2.3. I’ve created several different migrations without
#down, and no exceptino was raised. Maybe it’s something in your code, which you didn’t show a bit.EDIT 2: Just to recap, when you’re using up/down method, its your responsibility to raise
ActiveRecord::IrreversibleMigration. In other case, nothing will happen (#downdefined in AR will just return nil). The behaviour is different when you use#change. In some cases the mentioned exception can be raised by#inversedefined here: https://github.com/rails/rails/blob/565bfb9cd49285ebaa170141b4996c22ba81de43/activerecord/lib/active_record/migration/command_recorder.rb#L39 which is expected behaviour.