# How to UNDO ruby script/generate model table and migration

**URL:** <https://www.ruby-forum.com/t/how-to-undo-ruby-script-generate-model-table-and-migration/114600>\
**Category:** Rails\
**Created:** [September 17, 2007, 8:56am UTC](https://www.ruby-forum.com/t/how-to-undo-ruby-script-generate-model-table-and-migration/114600 "2007-09-17T08:56:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 17, 2007, 8:56am UTC](https://www.ruby-forum.com/t/how-to-undo-ruby-script-generate-model-table-and-migration/114600/1 "2007-09-17T08:56:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 17, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/how-to-undo-ruby-script-generate-model-table-and-migration/114600/2 "2007-09-17T17:31:48Z")

</div>

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 K.
