# Adding a column to a table

**URL:** <https://www.ruby-forum.com/t/adding-a-column-to-a-table/58856>\
**Category:** Rails\
**Created:** [April 26, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/adding-a-column-to-a-table/58856 "2006-04-26T16:51:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stepheneb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@stepheneb](https://www.ruby-forum.com/u/stepheneb)\
**Post date:** [April 26, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/adding-a-column-to-a-table/58856/1 "2006-04-26T16:51:30Z")

</div>

This is a real newbie question with what i’m sure will be a simple  
answer…

If i add a column a table (in a development application), how do i  
update my models to reflect this change?

Cheers,

Steve

---

<div class="post-metadata">

**Author:** ![stepheneb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@stepheneb](https://www.ruby-forum.com/u/stepheneb)\
**Post date:** [April 26, 2006, 4:55pm UTC](https://www.ruby-forum.com/t/adding-a-column-to-a-table/58856/2 "2006-04-26T16:55:00Z")

</div>

Stephen B. wrote:

> This is a real newbie question with what i’m sure will be a simple  
> answer…
> 
> If i add a column a table (in a development application), how do i  
> update my models to reflect this change?

Hi STeve,

You don’t actually have to update your models. If you look insde the  
model code, you’ll see it’s empty 🙂

You _may_ have to update the views/forms etc that the scaffold  
generated. Unfortunately there’s no way to ncrementally do this, you  
just have to destroy, then re-generate the scaffold (or just add the  
field by hand).

Alan

---

<div class="post-metadata">

**Author:** ![stepheneb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@stepheneb](https://www.ruby-forum.com/u/stepheneb)\
**Post date:** [April 26, 2006, 4:57pm UTC](https://www.ruby-forum.com/t/adding-a-column-to-a-table/58856/3 "2006-04-26T16:57:29Z")

</div>

If there’s nothing special your model needs to do with the column, you  
don’t have to do anything. In development mode, your application will be  
magically aware of the new field instantly.

If there’s something your model needs to know about the field, like a  
foreign-key relationship (belongs\_to, has\_many, etc.) or an  
attr\_accessor declaration or something like that, then you put that in  
your model and you’re all set.

In production mode, when you make changes like this, you need to restart  
the application, either by restrting the webserver or restarting any  
FCGI processes, depending on your production environment.

Stephen B. wrote:

> This is a real newbie question with what i’m sure will be a simple  
> answer…
> 
> If i add a column a table (in a development application), how do i  
> update my models to reflect this change?
> 
> Cheers,
> 
> Steve

---

<div class="post-metadata">

**Author:** ![stepheneb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@stepheneb](https://www.ruby-forum.com/u/stepheneb)\
**Post date:** [April 26, 2006, 4:57pm UTC](https://www.ruby-forum.com/t/adding-a-column-to-a-table/58856/4 "2006-04-26T16:57:48Z")

</div>

On 4/26/06, Stephen B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This is a real newbie question with what i’m sure will be a simple answer…
> 
> If i add a column a table (in a development application), how do i  
> update my models to reflect this change?
> 
> Cheers,
> 
> Steve

It will happen automatically. Your models determine which attributes  
they have from the database on their own.  
In development mode, that will happen every time a page loads. In  
production, you need to restart the app.

---

<div class="post-metadata">

**Author:** ![stepheneb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@stepheneb](https://www.ruby-forum.com/u/stepheneb)\
**Post date:** [April 26, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/adding-a-column-to-a-table/58856/5 "2006-04-26T17:01:07Z")

</div>

That’s embarrassingly simple :0)

Cheers,

Steve
