Forum: Ruby on Rails Adding a column to a table

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
882cc23c77c5c6d27613c51396a02a0d?d=identicon&s=25 Stephen Bartholomew (Guest)
on 2006-04-26 16:51
(Received via mailing list)
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
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-04-26 16:55
Stephen Bartholomew 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
34f5b045aec62235c17458650ea75353?d=identicon&s=25 Steve Koppelman (hatless)
on 2006-04-26 16:57
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 Bartholomew 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
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-04-26 16:57
(Received via mailing list)
On 4/26/06, Stephen Bartholomew <sb@2404.co.uk> 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.
882cc23c77c5c6d27613c51396a02a0d?d=identicon&s=25 Stephen Bartholomew (Guest)
on 2006-04-26 17:01
(Received via mailing list)
That's embarrassingly simple :0)

Cheers,

Steve
This topic is locked and can not be replied to.