UPDATE: I’ve been using this method for awhile now: http://railspikes.com/2008/2/1/loading-seed-data
Seed data is data that the app is dependent on. It is data that has to exist if you were to wipe the database clean and reload your schema. Some examples would be a list of cities/states, a list of categories, or the initial ‘admin’ user account.
Most people looking at this thread want seed data rather than to populate their database with test/generated content. For the latter, you can go the route below or try Forgery
This is a response to the email I’ve been getting asking me how to use fixtures to load data into a database.
You want to create dummy entries in your Rails app, either for testing, for development, or for production, to make your site appear popular. Whatever the reason, populating your database can be done easily using fixtures.
While rake/fixtures/migrations can get a lot more complex, this will be a brief introductory example.
Initial App setup
$ rails characters
$ cd characters/
Edit config/database.yml – We only need a development database. So open up PHPMyAdmin or the MySQL command shell and:
mysql> CREATE database characters_development;
Query OK, 1 row affected (0.00 sec)
(I’m assuming you’re using MySQL. You can use anything; SQLite, Postgres, etc..)
Create a model and a table in the database (using a migration)
$ script/generate model Character
$ vim db/migrate/001_create_characters.rb
class CreateCharacters < ActiveRecord::Migration
create_table :characters do |t|
t.string :name, :alias, :motto
Now migrate development (default environment):
$ rake db:migrate
Create the characters fixture
$ vim test/fixtures/characters.yml
Continue reading How To Use Fixtures to Populate Your Database in Rails