How to add a new column to a table using RadRails

Hi all,

I am new to ROR and I use RadRails for ROR. I start a project and create
a model,a scaffold, and a table. It works fine. The table contains two
columns. Later on I need to add one more column to the table and I find
I can’t update the table. I wonder if anyone out there please gives me a
hand.

Thanks,

Li

############# original table with 2 columns in file
db\migrate\001_create_employees.rb

class CreateEmployees < ActiveRecord::Migration
def self.up
create_table :employees do |t|
t.column :name,:string
t.column :hiredate,:date
end
end

def self.down
drop_table :employees
end
end

########### in file db\schema.rb
ActiveRecord::Schema.define(:version => 1) do

create_table “employees”, :force => true do |t|
t.column “name”, :string
t.column “hiredate”, :date
end

end

######later on add one more column to the new table

class CreateEmployees < ActiveRecord::Migration
def self.up
create_table :employees do |t|
t.column :name,:string
t.column :hiredate,:date
t.column :salary,:float
end
end

def self.down
drop_table :employees
end
end

########### in file db\schema.rb

ActiveRecord::Schema.define(:version => 1) do

create_table “employees”, :force => true do |t|
t.column “name”, :string
t.column “hiredate”, :date
end

end

##there is no change to the schema.rb. WHY??? and how?

On Mon, 31 Dec 2007 16:44:20 +0100, Li Chen wrote:

I am new to ROR and I use RadRails for ROR. I start a project and create
a model,a scaffold, and a table. It works fine. The table contains two
columns. Later on I need to add one more column to the table and I find
I can’t update the table. I wonder if anyone out there please gives me a
hand.

Get a second opinion first. Err, I mean, run this by a more experience
RoR person. try:

rake db:migrate VERSION=0
rake db:migrate

the first command will drop the tables, the second command will
re-create
the tables. Data will be lost. Data will be lost. Data will be lost.
Data will be lost. Data will be lost. Data will be lost. Data will be
lost. Data will be lost. Data will be lost. Data will be lost.

-Thufir

Hi, it two ways that you can do it:
Not So The Rails Way

a) rake db:migrate VERSION=0
b) edit and save the migration beginning with “001_”
c) rake db:migrate

More So The Rails Way

a) script/generate migration <the_name_of_my_migration_file>
b) edit and save the migration file that has been generated.

Note: If you need info on how to properly add a column, please consult
pages 260 - 265 of AWDwR2.

Good luck,

-Conrad