# Problem with migrations

**URL:** <https://www.ruby-forum.com/t/problem-with-migrations/97830>\
**Category:** Rails\
**Created:** [July 10, 2006, 9:24pm UTC](https://www.ruby-forum.com/t/problem-with-migrations/97830 "2006-07-10T21:24:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bob\_brazeau](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/db5fbb/32.png) [@bob\_brazeau](https://www.ruby-forum.com/u/bob_brazeau)\
**Post date:** [July 10, 2006, 9:24pm UTC](https://www.ruby-forum.com/t/problem-with-migrations/97830/1 "2006-07-10T21:24:02Z")

</div>

I am trying to start my first project after going though the Depot  
application in prog prog’s book. For some reason one of my migrations  
keeps  
bombing. I just try to setup a couple tables with some default  
information  
and even with changing the name of the second table and other minor  
tweaks  
it just does not work. I am connected to the db, the first table does  
get  
filled out.

Any help is appreciated!

Here is what I’ve done so far:

> ruby script\generate model employees  
> ruby script\generate migration add\_employee\_data  
> ruby script\generate model cost\_codes  
> ruby script\generate migration add\_cost\_code\_data

Then inside the first 3 migrations everything goes ok -  
001  
class CreateEmployees \< ActiveRecord::Migration  
def self.up  
create\_table :employees do |t|  
t.column :employee\_number, :integer  
t.column :name, :string  
t.column :location, :string  
t.column :department, :integer  
t.column :company\_code, :string  
end  
end

def self.down  
drop\_table :employees  
end  
end

002  
class AddEmployeeData \< ActiveRecord::Migration  
def self.up  
Employee.create(  
:employee\_number =\> ‘1234’,  
:name =\> ‘Bob B’,  
:location =\> ‘Office’,  
:department =\> ‘07’,  
:company\_code =\> ‘003’)  
end

def self.down  
Employee.delete\_all  
end  
end

003  
class CreateCostCodes \< ActiveRecord::Migration  
def self.up  
create\_table :cost\_codes do |t|  
t.column :job, :integer  
t.column :code, :integer  
t.column :description, :string  
end  
end

def self.down  
drop\_table :cost\_codes  
end  
end

This is the migration that fails with an error of ‘uninitalized constant  
cost\_code’ Anyone know what I am doing wrong?

004  
class AddCodeCodeData \< ActiveRecord::Migration  
def self.up  
Costcode.create(  
:job =\> ‘0’,  
:code =\> ‘5001’,  
:description =\> ‘Other administrative (non-job related)’ )  
end

def self.down  
Costcode.delete\_all  
end  
end

---

<div class="post-metadata">

**Author:** ![bob\_brazeau](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/db5fbb/32.png) [@bob\_brazeau](https://www.ruby-forum.com/u/bob_brazeau)\
**Post date:** [July 10, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/problem-with-migrations/97830/2 "2006-07-10T21:30:14Z")

</div>

On 7/10/06, bob brazeau [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Any help is appreciated!

> Here is what I’ve done so far:
> 
> > ruby script\generate model employees  
> > ruby script\generate migration add\_employee\_data  
> > ruby script\generate model cost\_codes  
> > ruby script\generate migration add\_cost\_code\_data

Looks like you generated a plural cost\_codes model, did you mean to do  
that?

This is the migration that fails with an error of ’ uninitalized  
constant

> def self.down  
> Costcode.delete\_all  
> end  
> end

If indeed your model is named CodeCodes as specified in your generator  
statement above then you would need to replace each ‘Costcode’ with  
‘CostCodes’

Josh

---

<div class="post-metadata">

**Author:** ![bob\_brazeau](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/db5fbb/32.png) [@bob\_brazeau](https://www.ruby-forum.com/u/bob_brazeau)\
**Post date:** [July 10, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/problem-with-migrations/97830/3 "2006-07-10T21:30:23Z")

</div>

On Jul 10, 2006, at 12:22 PM, bob brazeau wrote:

> def self.down  
> def self.up  
> Costcode.create(  
> :job =\> ‘0’,  
> :code =\> ‘5001’,  
> :description =\> ‘Other administrative (non-job related)’ )  
> end
> 
> def self.down  
> Costcode.delete\_all  
> end  
> end

CamelCase class name for cost\_codes table would be:

CostCode

---

<div class="post-metadata">

**Author:** ![bob\_brazeau](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/db5fbb/32.png) [@bob\_brazeau](https://www.ruby-forum.com/u/bob_brazeau)\
**Post date:** [July 10, 2006, 9:53pm UTC](https://www.ruby-forum.com/t/problem-with-migrations/97830/4 "2006-07-10T21:53:30Z")

</div>

Thanks for the help guys, its working like a champ!

The camelcase and the mis-placed plural name was the problem.
