# Rails/Rake Migrations - Newbie Question

**URL:** <https://www.ruby-forum.com/t/rails-rake-migrations-newbie-question/183620>\
**Category:** Rails\
**Created:** [February 17, 2010, 2:13pm UTC](https://www.ruby-forum.com/t/rails-rake-migrations-newbie-question/183620 "2010-02-17T14:13:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@lukas](https://www.ruby-forum.com/u/lukas)\
**Post date:** [February 17, 2010, 2:13pm UTC](https://www.ruby-forum.com/t/rails-rake-migrations-newbie-question/183620/1 "2010-02-17T14:13:17Z")

</div>

Hello,

I have a problem understanding Rails/Rake migrations.

For example let’s say I have a migrate-script like this:

class CreateUsers \< ActiveRecord::Migration  
def self.up  
create\_table :users do |t|  
t.string :name  
t.string :username  
t.string :password  
t.string :email  
t.timestamps  
end

```
User.create :name=>"John

```

Smith", :email=\>“removed\_email\_address@domain.invalid”, :username=\>“js”,  
:password=“jsRules!”  
end

def self.down  
drop\_table :users  
end  
end

If I do a migration with db:reset it will update all tables, DELETE  
EVERYTHING, and then insert John S…

However, let’s say I want to add a

t.string :secret\_answer

to that model, and migrate it, what do I use?

I would like to keep all data already in DB and just have rake add one  
column to the table.

I tried migrate:redo, migrate.up etc. The latter even requires a  
Version value. What do I enter here?

Now this is obviously a very noobish question, but maybe one of you  
can clarify.

FYI, I’m using latest RoR with Aptana on Windows7 and mySQL as DB-  
backend.

Thanks,  
Lukas

---

<div class="post-metadata">

**Author:** ![lukas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@lukas](https://www.ruby-forum.com/u/lukas)\
**Post date:** [February 17, 2010, 2:41pm UTC](https://www.ruby-forum.com/t/rails-rake-migrations-newbie-question/183620/2 "2010-02-17T14:41:23Z")

</div>

On 17 February 2010 13:12, lukas [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> t.string :username
> 
> ```
> 
> drop\_table :users
> 
> to that model, and migrate it, what do I use?
> 
> I would like to keep all data already in DB and just have rake add one  
> column to the table.
> 
> I tried migrate:redo, migrate.up etc. The latter even requires a  
> Version value. What do I enter here?

To apply migrations that have not already been applied use  
rake db:migrate

[http://guides.rubyonrails.org/](http://guides.rubyonrails.org/) has a guide on migrations, but start  
with Getting Started if you have not already worked through that.  
Then work through the others.

Colin

---

<div class="post-metadata">

**Author:** ![lukas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@lukas](https://www.ruby-forum.com/u/lukas)\
**Post date:** [February 17, 2010, 3:17pm UTC](https://www.ruby-forum.com/t/rails-rake-migrations-newbie-question/183620/3 "2010-02-17T15:17:41Z")

</div>

Colin, Thanks.

You know, I first looked at Rails one year ago and knew this. But  
somehow I forgot it. Thanks for pointing knucklehead-me back to the  
basics. 🙂

I basically create new migrations and then db:migrate works like a  
charm.

Thanks!
