# Strange Migration Behaviour

**URL:** <https://www.ruby-forum.com/t/strange-migration-behaviour/108756>\
**Category:** Rails\
**Created:** [July 6, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/strange-migration-behaviour/108756 "2007-07-06T18:26:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [July 6, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/strange-migration-behaviour/108756/1 "2007-07-06T18:26:45Z")

</div>

Hi! I’m getting this strange migration error for this migration:

class CreateCustomers \< ActiveRecord::Migration  
def self.up  
Customer.create :name =\> ‘TEST’, :zone\_id =\> 0  
end

def self.down  
Customer.delete\_all  
end  
end

Produces:

# == CreateCustomers: migrating

– create({:name=\>“TEST”, :zone\_id=\>0})  
rake aborted!  
undefined method `create’ for  
#ActiveRecord::ConnectionAdapters::MysqlAdapter:0x46c2204

I “fixed” it by defining the customer model inside the migration. Why is  
happening this? (the same kind of migrations are working for all my  
models except “Customer”)

class CreateCustomers \< ActiveRecord::Migration  
class Customer \< ActiveRecord::Base  
end

def self.up  
Customer.create :name =\> ‘TEST’, :zone\_id =\> 0  
end

def self.down  
Customer.delete\_all  
end  
end

---

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [July 6, 2007, 7:11pm UTC](https://www.ruby-forum.com/t/strange-migration-behaviour/108756/2 "2007-07-06T19:11:51Z")

</div>

Perhaps a little “obvious”, but  
“eval(File.read(‘app/models/customer.rb’))” also works fine.

class CreateCustomers \< ActiveRecord::Migration

# Improvised fix. Why?

eval(File.read(‘app/models/customer.rb’))

def self.up  
Customer.create :name =\> ‘TEST’, :zone\_id =\> 0  
end

def self.down  
Customer.delete\_all  
end  
end

I think thisis related:  
[http://wiki.rubyonrails.org/rails/pages/TipsAndTricks](http://wiki.rubyonrails.org/rails/pages/TipsAndTricks), Adding Data to  
Migrations

I still don’t know why! ☹
