# Don't understand migrations

**URL:** <https://www.ruby-forum.com/t/dont-understand-migrations/135346>\
**Category:** Rails\
**Created:** [April 21, 2008, 1:05pm UTC](https://www.ruby-forum.com/t/dont-understand-migrations/135346 "2008-04-21T13:05:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [April 21, 2008, 1:05pm UTC](https://www.ruby-forum.com/t/dont-understand-migrations/135346/1 "2008-04-21T13:05:56Z")

</div>

If I use rake db:rollback it will delete a table I don’t want. Then I  
add another migration with a new table. Then I run db:migrate. The table  
I didn’t want is created again. How do I delete it so it doesn’t come  
back?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [April 21, 2008, 1:23pm UTC](https://www.ruby-forum.com/t/dont-understand-migrations/135346/2 "2008-04-21T13:23:28Z")

</div>

Example :

class CreateNewTable\< ActiveRecord::Migration  
def self.up  
create\_table :new\_tables do |t|  
t.column :name, :string  
end

drop\_table :old\_tables

#rename\_table :old\_tables, :new\_tables  
rename\_table :books, :libraries

#remove\_column(table\_name, column\_name)  
remove\_column :items, :price

#remove\_column(table\_name, column\_name)  
rename\_column “users”, “password”, “hashed\_password”

#add\_column table\_names, new\_column\_names  
add\_column “users”, “email”

end

def self.down  
drop\_table :lupa\_passwords  
end  
end

* * *

## ANOTHER SCENARIO

I created a series of migrations named 001\_migration.rb through  
007\_migration.rb. The last migration worked fine until I attempted to  
rollback to the previous version using

rake db:migrate VERSION=6

which dropped all the tables in my database.

Now the migration refuses to do anything, regardless of which version  
number I tell it to use. It always tried to run the latest version,  
which fails because the relevant tables do not exist. What is wrong?

ANSWER: My migration names were the same. Each migration filename must  
be different or you will receive errors.

Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)

* * *

FREE eBook Ruby

[http://teapoci.blogspot.com/search/label/eBook](http://teapoci.blogspot.com/search/label/eBook)

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [April 21, 2008, 1:36pm UTC](https://www.ruby-forum.com/t/dont-understand-migrations/135346/3 "2008-04-21T13:36:25Z")

</div>

Visit Indonesia 2008 wrote:

> Example :
> 
> class CreateNewTable\< ActiveRecord::Migration  
> def self.up  
> create\_table :new\_tables do |t|  
> t.column :name, :string  
> end
> 
> drop\_table :old\_tables

Thanks. Now I got it.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [April 21, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/dont-understand-migrations/135346/4 "2008-04-21T16:20:51Z")

</div>

Pål Bergström wrote:

> > class CreateNewTable\< ActiveRecord::Migration  
> > def self.up  
> > create\_table :new\_tables do |t|  
> > t.column :name, :string  
> > end
> > 
> > drop\_table :old\_tables

> Thanks. Now I got it.

Your customers won’t mind copying all the data from the old table to the  
new  
one. (-:

–  
Phlip
