views:

75

answers:

1

Hey Guys,

Just working through the Agile Web Development with Rails book and near the closing chapters of the book I had to rollback the db a few times using db:migrate VERSION=0 followed by the db:migrate command. However upon bringing the database back from the ground up, the add_test_data migration fails to add the test entries to the db as it had successfully done previously. Any Ideas? Im getting the following in the development log

Migrating to AddTestData (20091111225948) [4;36;1mSQL (0.0ms)[0m [0;1mselect sqlite_version(*)[0m

[4;35;1mProduct Load (1.0ms)[0m [0m SELECT "products".id FROM "products" WHERE ("products"."title" = 'Pragmatic Project Automation') LIMIT 1[0m

[4;36;1mProduct Load (0.0ms)[0m [0;1mSELECT "products".id FROM "products" WHERE ("products"."title" = 'Pragmatic Version Control') LIMIT 1[0m

[4;35;1mProduct Load (1.0ms)[0m [0mSELECT "products".id FROM "products" WHERE ("products"."title" = 'Pragmatic Unit Testing (C#)') LIMIT 1[0m

[4;36;1mSQL (1.0ms)[0m [0;1mINSERT INTO schema_migrations (version) VALUES ('20091111225948')[0m

The db is SQLite3, Ruby 1.8.6, Rails 2.3.4 and im developing on Windows (cringe)

A: 

Since you're using 2.3.4 I would use db:seed to add seed data.

Short of that I'd try renaming your sqlite database and running rake db:migrate again against an empty database. You might have to create a new empty development.sqlite3.

If neither of these work for you posting the contents of the migration would help.

Andy Gaskell
Hi Andy,Cheers for the tips, I transfered the code from the migration into seeds.rb. It turns out that the code was failing silently because I was creating the records using create as opposed to create! (which is what the Railscasts guy does). According to the trace, I had a typo in some validation code I had written previously. Problem solved! ah, the wonderful world of shopping cart applications :/
gcahill