# How to add a new column to a table using RadRails

**URL:** <https://www.ruby-forum.com/t/how-to-add-a-new-column-to-a-table-using-radrails/124652>\
**Category:** Rails\
**Created:** [December 31, 2007, 4:44pm UTC](https://www.ruby-forum.com/t/how-to-add-a-new-column-to-a-table-using-radrails/124652 "2007-12-31T16:44:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 31, 2007, 4:44pm UTC](https://www.ruby-forum.com/t/how-to-add-a-new-column-to-a-table-using-radrails/124652/1 "2007-12-31T16:44:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 31, 2007, 5:40pm UTC](https://www.ruby-forum.com/t/how-to-add-a-new-column-to-a-table-using-radrails/124652/2 "2007-12-31T17:40:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 31, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/how-to-add-a-new-column-to-a-table-using-radrails/124652/3 "2007-12-31T22:55:58Z")

</div>

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
