Forum: Ruby on Rails how to drop table and recreate the table using migrate

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Yan (Guest)
on 2007-01-29 22:07
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?
Phlip (Guest)
on 2007-01-29 22:17
(Received via mailing list)
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  <-- NOT a blog!!
unknown (Guest)
on 2007-01-29 22:27
(Received via mailing list)
rake db:migrate VERSION=0
rake db:migrate

good luck!
Tim
Yan (Guest)
on 2007-01-29 22:31
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.
Jim L. (Guest)
on 2007-01-29 22:50
(Received via mailing list)
> > 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.
Phlip (Guest)
on 2007-01-29 22:56
(Received via mailing list)
> > 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  <-- NOT a blog!!
Yan (Guest)
on 2007-01-29 23:04
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
askegg (Guest)
on 2007-01-30 00:32
(Received via mailing list)
On Jan 30, 7:40 am, "Jim L." <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.
This topic is locked and can not be replied to.