# How to drop table and recreate the table using migrate

**URL:** <https://www.ruby-forum.com/t/how-to-drop-table-and-recreate-the-table-using-migrate/83800>\
**Category:** Rails\
**Created:** [January 29, 2007, 9:07pm UTC](https://www.ruby-forum.com/t/how-to-drop-table-and-recreate-the-table-using-migrate/83800 "2007-01-29T21:07:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/3e96dc/32.png) [@yan](https://www.ruby-forum.com/u/yan)\
**Post date:** [January 29, 2007, 9:07pm UTC](https://www.ruby-forum.com/t/how-to-drop-table-and-recreate-the-table-using-migrate/83800/1 "2007-01-29T21:07:17Z")

</div>

I did something wrong during first migration. I would like to drop the  
table and call migration again to re-create the table. but don’t know  
the appropriate way to do it.

any idea?

---

<div class="post-metadata">

**Author:** ![yan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/3e96dc/32.png) [@yan](https://www.ruby-forum.com/u/yan)\
**Post date:** [January 29, 2007, 9:17pm UTC](https://www.ruby-forum.com/t/how-to-drop-table-and-recreate-the-table-using-migrate/83800/2 "2007-01-29T21:17:32Z")

</div>

Yan wrote:

> I did something wrong during first migration. I would like to drop the  
> table and call migration again to re-create the table. but don’t know  
> the appropriate way to do it.

Get into the database (maybe mysql -u root), drop the database, and  
recreate it.

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![yan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/3e96dc/32.png) [@yan](https://www.ruby-forum.com/u/yan)\
**Post date:** [January 29, 2007, 9:27pm UTC](https://www.ruby-forum.com/t/how-to-drop-table-and-recreate-the-table-using-migrate/83800/3 "2007-01-29T21:27:34Z")

</div>

rake db:migrate VERSION=0  
rake db:migrate

good luck!  
Tim

---

<div class="post-metadata">

**Author:** ![yan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/3e96dc/32.png) [@yan](https://www.ruby-forum.com/u/yan)\
**Post date:** [January 29, 2007, 9:31pm UTC](https://www.ruby-forum.com/t/how-to-drop-table-and-recreate-the-table-using-migrate/83800/4 "2007-01-29T21:31:36Z")

</div>

unknown wrote:

> rake db:migrate VERSION=0  
> rake db:migrate
> 
> good luck!  
> Tim

It doesn’t work. I don’t know why. It seems I have to go to mysql to  
drop the entire database.

---

<div class="post-metadata">

**Author:** ![yan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/3e96dc/32.png) [@yan](https://www.ruby-forum.com/u/yan)\
**Post date:** [January 29, 2007, 9:50pm UTC](https://www.ruby-forum.com/t/how-to-drop-table-and-recreate-the-table-using-migrate/83800/5 "2007-01-29T21:50:37Z")

</div>

> > rake db:migrate VERSION=0  
> > rake db:migrate
> 
> It doesn’t work. I don’t know why. It seems I have to go to mysql to  
> drop the entire database.

If something unexpected happens, the rake migrate task will leave it  
up to you to clean up manually. It’s not smart enough to recover from  
the many different things that can go wrong.

You can run your migrations first as

rake db:migrate --dry-run --trace

That’ll catch some possible errors before running the migration for  
real.

---

<div class="post-metadata">

**Author:** ![yan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/3e96dc/32.png) [@yan](https://www.ruby-forum.com/u/yan)\
**Post date:** [January 29, 2007, 9:56pm UTC](https://www.ruby-forum.com/t/how-to-drop-table-and-recreate-the-table-using-migrate/83800/6 "2007-01-29T21:56:40Z")

</div>

> > rake db:migrate VERSION=0  
> > rake db:migrate

Yan wrote:

> It doesn’t work.

It probably requires effective self.down methods. I suspect that  
_some_ people slack off on those. Not _me_, of course!

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![yan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/3e96dc/32.png) [@yan](https://www.ruby-forum.com/u/yan)\
**Post date:** [January 29, 2007, 10:04pm UTC](https://www.ruby-forum.com/t/how-to-drop-table-and-recreate-the-table-using-migrate/83800/7 "2007-01-29T22:04:35Z")

</div>

Jim L. wrote:

> > > rake db:migrate VERSION=0  
> > > rake db:migrate
> > 
> > It doesn’t work. I don’t know why. It seems I have to go to mysql to  
> > drop the entire database.
> 
> If something unexpected happens, the rake migrate task will leave it  
> up to you to clean up manually. It’s not smart enough to recover from  
> the many different things that can go wrong.
> 
> You can run your migrations first as
> 
> rake db:migrate --dry-run --trace
> 
> That’ll catch some possible errors before running the migration for  
> real.

Below is waht I got:  
\*\* Invoke db:migrate (first\_time)  
\*\* Invoke environment (first\_time)  
\*\* Execute (dry run) environment  
\*\* Execute (dry run) db:migrate

---

<div class="post-metadata">

**Author:** ![yan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/3e96dc/32.png) [@yan](https://www.ruby-forum.com/u/yan)\
**Post date:** [January 29, 2007, 11:32pm UTC](https://www.ruby-forum.com/t/how-to-drop-table-and-recreate-the-table-using-migrate/83800/8 "2007-01-29T23:32:02Z")

</div>

On Jan 30, 7:40 am, “Jim L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > rake db:migrate VERSION=0  
> > > rake db:migrate
> 
> > It doesn’t work. I don’t know why. It seems I have to go to mysql to  
> > drop the entire database.If something unexpected happens, the rake migrate task will leave it  
> > up to you to clean up manually. It’s not smart enough to recover from  
> > the many different things that can go wrong.

Yeah - that’s a bit of an issue if you don’t capture the correct steps  
to migrate back down.  
Personally, I check I can migrate up and back down each step of the  
way (unless data is being destroyed in the migration, which make them  
very scary).

> You can run your migrations first as
> 
> rake db:migrate --dry-run --trace
> 
> That’ll catch some possible errors before running the migration for real.

Nice tip.

I would also recommend looking at “:force=\>true” whenever you are  
creating a new table.
