Refer to Rails.env from AR only when Rails is defined

AR migration.rb depends on `Rails` constant here in an error message, but AR doesn't actually always depend on Rails, so this code could sometimes cause another weird error: "NameError: uninitialized constant Rails"

I'm not sure if this really is a problem, and what is a desirable way to address the problem if it actually is a problem, so let me ask the core team as a PR.