# Migrating with loosing data

**URL:** <https://www.ruby-forum.com/t/migrating-with-loosing-data/142187>\
**Category:** Rails\
**Created:** [July 4, 2008, 9:36am UTC](https://www.ruby-forum.com/t/migrating-with-loosing-data/142187 "2008-07-04T09:36:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [July 4, 2008, 9:36am UTC](https://www.ruby-forum.com/t/migrating-with-loosing-data/142187/1 "2008-07-04T09:36:37Z")

</div>

I have already created a migration. It adds 5 columns. Now I edit  
migration file and enter 2 more column.

How can I remigrate so that 2 new columns would be added without loosing  
data with db:migrate:reset?

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [July 4, 2008, 11:29am UTC](https://www.ruby-forum.com/t/migrating-with-loosing-data/142187/2 "2008-07-04T11:29:02Z")

</div>

On 04 Jul 2008, at 09:36, Vapor … wrote:

> I have already created a migration. It adds 5 columns. Now I edit  
> migration file and enter 2 more column.
> 
> How can I remigrate so that 2 new columns would be added without  
> loosing  
> data with db:migrate:reset?

By putting it in a new migration file instead of adding it to an  
already deployed one.

script/generate migration AddTwoMoreColumns

and then in the migration (assuming you are using Rails 2.1):

class AddTimeZoneToUser \< ActiveRecord::Migration  
def self.up  
change\_table :users do |t|  
t.string :time\_zone  
t.belongs\_to :role  
end  
end

def self.down  
change\_table :users do |t|  
t.remove :time\_zone  
t.remove\_belongs\_to :role  
end  
end  
end

(example taken from:  
[Rolling with Rails 2.1 - The First Full Tutorial - Part 1 | AkitaOnRails.com](http://www.akitaonrails.com/2008/5/25/rolling-with-rails-2-1-the-first-full-tutorial-part-1))

Time to go pick up a book and start reading about how to use Rails.  
The Rails Way would be a good start.

Best regards

Peter De Berdt
