# Problem with creating migration files

**URL:** <https://www.ruby-forum.com/t/problem-with-creating-migration-files/154207>\
**Category:** Rails\
**Created:** [November 26, 2008, 12:51pm UTC](https://www.ruby-forum.com/t/problem-with-creating-migration-files/154207 "2008-11-26T12:51:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![indu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/eada6e/32.png) [@indu](https://www.ruby-forum.com/u/indu)\
**Post date:** [November 26, 2008, 12:51pm UTC](https://www.ruby-forum.com/t/problem-with-creating-migration-files/154207/1 "2008-11-26T12:51:13Z")

</div>

Hello ,

I am a ROR beginner. I have a controller named “users” and the  
corresponding view,model created using the command “ruby script/generate  
scaffold user name:string”.By running the command rake db:migrate will  
create the table “users” with a field “name” and the migration file  
created automatically is “001\_create\_users.rb”. Now when I tried to add  
one more column “password” ,by creating a new migration file using the  
command “ruby script/generate migration create\_users” an error is  
occuring  
like “Another file named 001\_create\_users.rb already exists”. May any  
one let me know what is the problem? I am using the right way or not?

Thanks in advance  
Indu

---

<div class="post-metadata">

**Author:** ![indu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/eada6e/32.png) [@indu](https://www.ruby-forum.com/u/indu)\
**Post date:** [November 26, 2008, 2:05pm UTC](https://www.ruby-forum.com/t/problem-with-creating-migration-files/154207/2 "2008-11-26T14:05:37Z")

</div>

Once a migration is created with the scaffold command it cannot be  
altered with the scaffold command. Only manually. However, once a  
migration file has been used by running rake db:migrate, you are not  
recommended to alter this file in a real production site, but rather  
you must make a new migration file, but not using scaffold:

script/generate migration AddPasswordColumn

This command would create a new migration file where you can add/alter/  
delete database columns and schema.

However, if you are testing and want to redo your first scaffold  
command:

rake db:migrate VERSION=0

And now edit the file and rerun:

rake db:migrate

Hank

---

<div class="post-metadata">

**Author:** ![indu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/eada6e/32.png) [@indu](https://www.ruby-forum.com/u/indu)\
**Post date:** [November 27, 2008, 5:38am UTC](https://www.ruby-forum.com/t/problem-with-creating-migration-files/154207/3 "2008-11-27T05:38:47Z")

</div>

Thank you for your response and solved my issue

---

<div class="post-metadata">

**Author:** ![indu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/eada6e/32.png) [@indu](https://www.ruby-forum.com/u/indu)\
**Post date:** [November 27, 2008, 6:14am UTC](https://www.ruby-forum.com/t/problem-with-creating-migration-files/154207/4 "2008-11-27T06:14:51Z")

</div>

Hi Indu  
Did u start the project?  
After running script/generate migration AddPasswordColumn you can do  
like  
In self.up  
add\_column :users,:password, :string

and may write in self.down (only if needed)

remove\_column :users, :password

```
  Then as usual rake db:migrate

```

Sijo

---

<div class="post-metadata">

**Author:** ![indu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/eada6e/32.png) [@indu](https://www.ruby-forum.com/u/indu)\
**Post date:** [November 27, 2008, 12:53pm UTC](https://www.ruby-forum.com/t/problem-with-creating-migration-files/154207/5 "2008-11-27T12:53:15Z")

</div>

Sijo Kg wrote:

> Hi Indu  
> Did u start the project?  
> After running script/generate migration AddPasswordColumn you can do  
> like  
> In self.up  
> add\_column :users,:password, :string
> 
> and may write in self.down (only if needed)
> 
> remove\_column :users, :password
> 
> ```
> Then as usual rake db:migrate
> 
> ```
> 
> Sijo

Thank u Sijo. Just trying on it. Any idea of saving the encoded  
password into the database.?

---

<div class="post-metadata">

**Author:** ![indu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/eada6e/32.png) [@indu](https://www.ruby-forum.com/u/indu)\
**Post date:** [November 28, 2008, 9:02am UTC](https://www.ruby-forum.com/t/problem-with-creating-migration-files/154207/6 "2008-11-28T09:02:37Z")

</div>

Hi  
Suppose there is a User model So in the view you have

\<%= password\_field ‘user’, ‘password’ %\>

  
Now write in User model

before\_create :protect\_password  
def protect\_password  
self.password = Digest::MD5.hexdigest(self.password)  
end

```
   There may be also other ways for doing this

```

Sijo

---

<div class="post-metadata">

**Author:** ![indu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/eada6e/32.png) [@indu](https://www.ruby-forum.com/u/indu)\
**Post date:** [November 28, 2008, 11:39am UTC](https://www.ruby-forum.com/t/problem-with-creating-migration-files/154207/7 "2008-11-28T11:39:20Z")

</div>

Sijo Kg wrote:

> Hi  
> Suppose there is a User model So in the view you have
> 
> \<%= password\_field ‘user’, ‘password’ %\>
> 
>   
> Now write in User model
> 
> before\_create :protect\_password  
> def protect\_password  
> self.password = Digest::MD5.hexdigest(self.password)  
> end
> 
> ```
> There may be also other ways for doing this
> 
> ```
> 
> Sijo

Thank you so much for your help. I tried this one and can save the  
encrypted password.
