Data migration using find_by_name

I am trying to set an attribute of a model based on a find_by_name search but it will always return the ID of 1. When i run this same search in the console it returns me the correct ID (6)

class LoadDefaultUser < ActiveRecord::Migration   def self.up     #department = Department.find_by_name("All Departments") <-- this always returns ID of 1 for the migration. Returns ID of 6 in console     #department = Department.find_by_id(6) <-- this always returns ID of 1 for the migration. Returns ID of 6 in console     department = 6 # this sets the department_id correctly so i know it should work???

    user = User.create(       :name => 'Administrator',       :department_id => department);     user.save!   end

  def self.down   end end