Problem with migrations

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

On 7/10/06, bob brazeau [email protected] 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

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

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs