when creating a table, i use script/generate migration tablename..and when i am done with adding fields, i type rake migrate. now what do i do if i want to add additional fields to the table? do i just make the modifications to the file that was created in the db directory and then rake migrate again? if so, i did, but my changes did not appear in the table. or do i need to generate another migration table? thanks for the help -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Migrate applies changes, moving the database from one state to the next, until it is at the latest. Migrations capture a set of changes in numbered files. When you do ''rake migrate'' those changes are applied to your database in sequential order and the final number is recorded in a table called ''schema_version''. If you run ''rake migrate'' again, the schema version is compared to the highest numbered migration. If the numbers match then the database is considered to be at the latest schema version and no migrations are performed. If you have previously run a migration and you want to add columns you have 2 choices: 1) you can reverse the previous migration or 2) you can create a new migration. I tend to do #1 if I am working on some changes and I simply forgot something and I have not yet released the new version. #2 is the primary mode of operation for migrations. Reversing a migration assumes you have implemented the ''down'' method. If you have done this then you simple say ''rake migrate VERSION=[some version number]''. For example, let''s say your latest migration is 005_add_project_table and that you have already done a ''rake migrate''. To revert to 4 you would do this: rake migrate VERSION=4 Good luck. -Kelly On 8/22/06, koloa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > when creating a table, i use script/generate migration tablename..and > when i am done with adding fields, i type rake migrate. now what do i do > if i want to add additional fields to the table? do i just make the > modifications to the file that was created in the db directory and then > rake migrate again? if so, i did, but my changes did not appear in the > table. or do i need to generate another migration table? > > > thanks for the help > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Koloa, The whole idea behind migrations is that each change you make goes into a new version. To add a new field, create a new migration file: script/generate migration adding_new_field and then add edit that file and add add_column :table_name, :new_field_name for each of the new fields that you have to the self.up method. Remember to add remove_column :table_name, :new_field_name to the self.down method for each of the new field. Hammed On 8/23/06, koloa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > when creating a table, i use script/generate migration tablename..and > when i am done with adding fields, i type rake migrate. now what do i do > if i want to add additional fields to the table? do i just make the > modifications to the file that was created in the db directory and then > rake migrate again? if so, i did, but my changes did not appear in the > table. or do i need to generate another migration table? > > > thanks for the help > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
ok, so i think was incorrectly using rake migrate. for every new table i created, i created a new migration and rake migrated it. nuts. hi Hammed, if i have a table called profiles and the file name is create_profiles_version1, class Profiles< ActiveRecord::Migration def self.up create_table :Profiles do |table| table.column :name, :string end end def self.down drop_table :Profiles end end and now id like to create a new profiles table, do i script/generate migrations profiles? and then in self.up do add_column somecolumnname ? afterwards type rake migrate? thanks all for the response. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
koloa wrote:> ok, so i think was incorrectly using rake migrate. for every new table i > created, i created a new migration and rake migrated it. nuts.Shrug, that''s pretty much what I do.> and now id like to create a new profiles table, do i script/generate > migrations profiles? and then in self.up do add_column somecolumnname ? > > afterwards type rake migrate?Pretty much, apart from the fact that you don''t actually create a "new" table, merely change the existing one. And I''d probably name the migration akin to AddStuffToProfiles, but each to his own. -- Jakob Skjerning - http://mentalized.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
>and now id like to create a new profiles table, do i script/generateI''m assuming you meant to say you''d like to create a new FIELD in the existing profiles table (you can''t have two tables named the same). If so, you''re right, create a new migration script/generate migration add_new_field_to_profile This will create a new migration file called something like 009_add_new_field_to_profile. Edit this migration file: class AddNewFieldToProfile< ActiveRecord::Migration def self.up add_column "profiles,"new_column" end def self.down remove_column "profiles", "new_column" end end when you run rake migrate next, the new column will be added to your table. If you''d like to roll back this change and remove the column, try rake migrate VERSION=8 Hammed On 8/23/06, koloa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > ok, so i think was incorrectly using rake migrate. for every new table i > created, i created a new migration and rake migrated it. nuts. > > hi Hammed, > > if i have a table called profiles and the file name is > create_profiles_version1, > > class Profiles< ActiveRecord::Migration > > def self.up > create_table :Profiles do |table| > table.column :name, :string > end > end > > def self.down > drop_table :Profiles > end > end > > > and now id like to create a new profiles table, do i script/generate > migrations profiles? and then in self.up do add_column somecolumnname ? > > afterwards type rake migrate? > > > thanks all for the response. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---