Hi everyone,
I have a large database I need to populate with data before initially running the application. Is it best to do this in an external rake task or inside migrations?
Sincerely, Tyler
Hi everyone,
I have a large database I need to populate with data before initially running the application. Is it best to do this in an external rake task or inside migrations?
Sincerely, Tyler
The file db/seeds.rb
is designed for this purpose. It should have been generated automatically when you created the Rails project. It has a comment at the top that explains how to use it:
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Major.create(:name => 'Daley', :city => cities.first)
After you've populated it, use rake db:seed
to populate the database with the seed data.