I''m having trouble modifying an existng database. My initial command to create was: ruby script/generate model Album title:string picture:string description:string price:float itemType:string Being that I forgot to put artist name I tried to go into the migrations file, set :force => true and added t.string :artist into the the create_table block, and then add_index :albums, :artist after it. so the new modified version looks like this: def self.up create_table :albums, :force => true do |t| t.string :artist t.string :title t.float :price t.string :description t.string :itemType t.string :picture t.timestamps end add_index :albums, :artist end I ran db:migrate and the changes still haven''t taken place....am I missing something here? Thanks Jon --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 25, 12:38 pm, Jon <jonli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m having trouble modifying an existng database. > > My initial command to create was: > ruby script/generate model Album title:string picture:string > description:string price:float itemType:string > > Being that I forgot to put artist name I tried to go into the > migrations file, set :force => true > and added t.string :artist into the the create_table block, and then > add_index :albums, :artist after it. so the new modified version > looks like this: > > def self.up > create_table :albums, :force => true do |t| > t.string :artist > t.string :title > t.float :price > t.string :description > t.string :itemType > t.string :picture > > t.timestamps > end > > add_index :albums, :artist > end > > I ran db:migrate and the changes still haven''t taken place....am I > missing something here? > > Thanks > > JonThat''s not how it is supposed to work. rake db:migrate will only run migrations higher than the current version as reported by rake db:version. If you want to re-run that migration (assuming you haven''t entered data yet), you can issue a rake db:rollback afterwhich you can run rake db:migrate --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 25 Sep 2008, at 05:38, Jon <jonliu81-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m having trouble modifying an existng database. > > My initial command to create was: > ruby script/generate model Album title:string picture:string > description:string price:float itemType:string > > Being that I forgot to put artist name I tried to go into the > migrations file, set :force => true > and added t.string :artist into the the create_table block, and then > add_index :albums, :artist after it. so the new modified version > looks like this: > > def self.up > create_table :albums, :force => true do |t| > t.string :artist > t.string :title > t.float :price > t.string :description > t.string :itemType > t.string :picture > > t.timestamps > end > > add_index :albums, :artist > end > > I ran db:migrate and the changes still haven''t taken place....am I > missing something here? >Yes. Rails keeps track of which migrations have run and which ones haven''t so running db:migrate again does nothing. You need to migrate down one version and back up again. Rake db:migrate:redo does exactly that if my memory is correct Fred> Thanks > > Jon > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Fred, Thanks. So I ran rake db:migrate VERSION=0. Then I tried to view my table structure under the console command line, to which I got an error(as expected since we roll back to version 0) I ran the rake db:migrate again and now I have my updated table. Why do you have to rollback a version though? If you set force to true, shouldn''t rails see this and make the change in the db structure? Let''s say I have data(which I did) in the table, and I want to keep that data. Rolling back to version 0 erases all records in the table, how would I do this without erasing all the exisiting records? Thanks for the insight. Jon On Wed, Sep 24, 2008 at 10:48 PM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 25 Sep 2008, at 05:38, Jon <jonliu81-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m having trouble modifying an existng database. > > > > My initial command to create was: > > ruby script/generate model Album title:string picture:string > > description:string price:float itemType:string > > > > Being that I forgot to put artist name I tried to go into the > > migrations file, set :force => true > > and added t.string :artist into the the create_table block, and then > > add_index :albums, :artist after it. so the new modified version > > looks like this: > > > > def self.up > > create_table :albums, :force => true do |t| > > t.string :artist > > t.string :title > > t.float :price > > t.string :description > > t.string :itemType > > t.string :picture > > > > t.timestamps > > end > > > > add_index :albums, :artist > > end > > > > I ran db:migrate and the changes still haven''t taken place....am I > > missing something here? > > > Yes. Rails keeps track of which migrations have run and which ones > haven''t so running db:migrate again does nothing. You need to migrate > down one version and back up again. Rake db:migrate:redo does exactly > that if my memory is correct > > Fred > > Thanks > > > > Jon > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 25, 3:01 pm, "Jon Liu" <jonli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Fred, > Thanks. > > So I ran rake db:migrate VERSION=0. Then I tried to view my table structure > under the console command line, to which I got an error(as expected since we > roll back to version 0) > > I ran the rake db:migrate again and now I have my updated table. > > Why do you have to rollback a version though? If you set force to true, > shouldn''t rails see this and make the change in the db structure? > Let''s say I have data(which I did) in the table, and I want to keep that > data. Rolling back to version 0 erases all records in the table, how would > I do this without erasing all the exisiting records? Thanks for the > insight. >Like I said, Rails tracks which migrations have been run and which hasn''t. Setting :force => true is irrelevant: the migration has been run and so rails does not look at it. As far as preserving data goes, you didn''t have to migrate down to 0 - you only have to go far enough to undo the migration you edited. If that is not acceptable (because there is data in that table or because there are other migrations in the way) then you should write a migration that just performs the changes you want. Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---