views:

237

answers:

3

Im trying to add an extra field to one of my tables.

Ive added the field in the migration file (under db\migrate) then ran 'rake db:migrate' which ran without troubles and my text editor even told me my schema.db file has been updated and needs to refresh.

The schema file does not contain my new field and any attempts to reference the field from my views fail miserably.

How do I do this? It is possible to update a table with an extra field via rails without having to totally drop and recreate the database again?

Thanks

Evolve

A: 
JRL
+1  A: 

Solved my own Question..

Basically rather than edit the original mirate files generated when you run scaffolding you create a new migrate file just for what you want to acheive:

http://guides.rubyonrails.org/migrations.html#creating-a-standalone-migration

Evolve
+2  A: 

You should always create a new migration file when adding/changing something in the database. This is the purpose of migrations. A migration file should have the ability to make the new change and undo the change. This way if something goes wrong or you changed your mind you can easily roll back to a previous migration.

The following link's sections labeled 'Anatomy of a Migration' and 'Writing a Migration' might be of help to you.

http://guides.rubyonrails.org/migrations.html

jluebbert