Summercool Summercool
2007-Sep-17 06:56 UTC
how to UNDO ruby script/generate model table and migration
Let''s say I did the C:\rails\depot> ruby script/generate model line_item and then forgot to modify the 007_create_line_items.rb to add the table fields, but have done the C:\rails\depot> rake db:migrate so in this case, how can i undo them and restart? I tried C:\rails\depot> rake db:migrate VERSION=6 to remove the table, and then C:\rails\depot> ruby script/destroy model line_item and then start from the very beginning... generate the model, edit the 007_create_line_items.rb, and rake db:migrate... but rake will report the table line_items doesn''t exist: C:\rails\depot>rake db:migrate (in C:/rails/depot) -- execute("alter table line_items add constraint fk_line_item_products \n f oreign key (product_id) references products(id)") rake aborted! Mysql::Error: Table ''depot_development.line_items'' doesn''t exist: alter table li ne_items add constraint fk_line_item_products foreign key (product_id) references products(id) (See full trace by running task with --trace) So how can it be done? How can the migration create the table once again? -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Kaufman
2007-Sep-17 15:30 UTC
Re: how to UNDO ruby script/generate model table and migration
Looks like the table did not get dropped. Either the down action in the Migration did not include the drop command or the command rake db:migrate VERSION=6 did not succeed. To resolve the issue you need to take one of the following steps: rake db:reset #Only works in Edge or w/ Sake drop your database, recreate it and remigrate drop the specific table that was causing the problem either from the command line or from a gui client. add :force => true to your migrations table create line (think carefully before doing this one) Good Luck, Rob Kaufman On 9/16/07, Summercool Summercool <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Let''s say I did the > > C:\rails\depot> ruby script/generate model line_item > and then forgot to modify the > > 007_create_line_items.rb > > to add the table fields, but have done the > > C:\rails\depot> rake db:migrate > > so in this case, how can i undo them and restart? > > I tried > > C:\rails\depot> rake db:migrate VERSION=6 > > to remove the table, and then > > C:\rails\depot> ruby script/destroy model line_item > > and then start from the very beginning... generate the model, edit the > 007_create_line_items.rb, and rake db:migrate... > > but rake will report the table line_items doesn''t exist: > > C:\rails\depot>rake db:migrate > (in C:/rails/depot) > -- execute("alter table line_items add constraint fk_line_item_products > \n f > oreign key (product_id) references products(id)") > rake aborted! > Mysql::Error: Table ''depot_development.line_items'' doesn''t exist: alter > table li > ne_items add constraint fk_line_item_products > foreign key (product_id) references products(id) > > (See full trace by running task with --trace) > > So how can it be done? How can the migration create the table once > again? > -- > 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?hl=en -~----------~----~----~----~------~----~------~--~---