Migrtion with data

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

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

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

Thanks for all the reply

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs