# Initialization of class variables during migration

**URL:** <https://www.ruby-forum.com/t/initialization-of-class-variables-during-migration/103738>\
**Category:** Rails\
**Created:** [May 9, 2007, 8:26pm UTC](https://www.ruby-forum.com/t/initialization-of-class-variables-during-migration/103738 "2007-05-09T20:26:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [May 9, 2007, 8:26pm UTC](https://www.ruby-forum.com/t/initialization-of-class-variables-during-migration/103738/1 "2007-05-09T20:26:35Z")

</div>

Hi all-

Perhaps this is not a best practice, but we currently have class  
variables in several class that are initialized by calls to AR  
classes. For example:

class Foo \< ActiveRecord::Base  
@@my\_class\_var = Bar.find(:first)  
end

When using migrations to set-up a new environment, this fails as the  
‘bars’ table does not yet exist when the environment is loaded. Any  
thoughts on how to work through this? I imagine this is fairly  
common, but like I said maybe this is not a best practice.

Thanks,  
Josh
