Debug Output For Migrations in Ruby on Rails 4

Posted by Ben Reubenstein Tue, 31 Jul 2007 13:04:00 GMT

Today I was doing some massive migrations that rocked the very foundations of an app I am working on. Problem was that during the migration I was moving objects around the database and validations were failing for my saves. To get some debugging going, I started out trying to write to the logger, with some good ol' logger.debug, but that does not work within a migration. To output information in a migration, use puts. So for example to see all the errors that prevented object g from being saved:
class MyMigration < ActiveRecord::Migration
  def self.up
    g = => "name" )
      #More object manipulation here
      g.errors.each do |x|
        puts x

  def self.down
    #Down Method Code Here