# Migrtion with data

**URL:** <https://www.ruby-forum.com/t/migrtion-with-data/145031>\
**Category:** Rails\
**Created:** [August 5, 2008, 2:06pm UTC](https://www.ruby-forum.com/t/migrtion-with-data/145031 "2008-08-05T14:06:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [August 5, 2008, 2:06pm UTC](https://www.ruby-forum.com/t/migrtion-with-data/145031/1 "2008-08-05T14:06:21Z")

</div>

Hi  
I have created a model Category Then in its migration file I have  
def self.up  
create\_table :categories do |t|  
t.column :name, :string, :limit=\>80  
end  
end  
def self.down  
drop\_table :categories  
end

```
  Here before doing migrate I have to enter data to this since this

```

is a master table.So I have to enter data  
id name  
1 category1  
2 category2  
3 category3

```
     Could you please tell how I can do this?Is this possible.And

```

also what shud be there in self.down method?

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [August 5, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/migrtion-with-data/145031/2 "2008-08-05T17:36:24Z")

</div>

Not sure I entirely understand you, but, after the create\_table you  
could do:

Category.create(:name =\> “category1”)  
Category.create(:name =\> “category2”)  
Category.create(:name =\> “category3”)

and in the down do  
Category.delete\_all

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [August 5, 2008, 2:12pm UTC](https://www.ruby-forum.com/t/migrtion-with-data/145031/3 "2008-08-05T14:12:43Z")

</div>

ActiveRecord::Base.connection.execute (“insert into categories (id,name)  
values(1,‘categody1’),(2,“category2”);”)

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [August 6, 2008, 6:10am UTC](https://www.ruby-forum.com/t/migrtion-with-data/145031/4 "2008-08-06T06:10:25Z")

</div>

Thanks for all the reply
