Quick tips about using rake to manage your database schema and fixture data 6
I just discovered (with a little help from my friends) that there’s an easy way to load your development database with your fixture data (you are using fixtures, aren’t you? If not, you really should learn about them). Even if you’re not writing tests (though you should be) you can use your fixture data as an easy way to modify your database data. These things are especially great if you’re in a team environment and want to keep everyone’s development database schema and data synchronized.
First, go to the top directory of your rails app and type:
rake db_schema_dump
This creates a file called schema.db in your \db folder. You can then check in/commit this file into your source control system for others on your team. Unlike the development_structure.sql file, schema.db is not automatically updated when you rake your tests, so you’ll need to run this manually anytime you edit your table schema.
When you get latest/update from source control, you can update your local database this way:
rake db_schema_import
Warning Will Rogers, this will wipe out any data you had in your database (but you probably won’t care).
And anytime you want to populate your database with your fixture data, just do this:
rake load_fixtures
Presto, all your data is slurped into your database tables. Fire up webbrick and play with your site, and all of your fixture data is now “live” in the database for you.



Good timing. I knew there was a way to auto import data, but I was about to do this via my sql create script. Since there are shortcuts to almost everything else in Rails, I was sure I missed something. thanks!
I'm having problems loading my fixtures, I think because the db has foreign key constraints. I've read the RoR wiki about disabling contrains, but the solution seems cryptic to me. Do you have any ideas or have you encountered this problem before?
Chris, I think there are some things you need to do to make sure the loader won't violate contraints as it deletes/inserts your fixture data. But it doesn't look too hard. Basically you need to either turn off the contraint checking temporarily, or tell the loader in which order to load the tables (default is alphabetical fixture name order, I guess). Check out these links:
Hopefully these will get you going. Can you post again or drop me an email if you get it working? If those don't help let me know that, too.
Thanks for the links, Jeff. I had already found the first one, but wasn't even sure how to create a "task." The other two were new to me.
For the time being, I removed the constraints entirely from the schema. My fixtures loaded fine after that, and the app seems to work just fine without them.
In the longer term, I'm not sure if I'll need the constraints since I'm not updating lots of tables in sequence, but I have a feeling I'll need to put them back at some point.
I'm continually amazed at how quickly development is with rails. It's a drag to have to use .NET for everything at work.
By immersing ourselves meditatively in the general intentions of modes of consciousness, we discover that the fundamental form of this universal synthesis (de facto) is unified synthetically.
I assert, certainly, that, in respect of the intelligible character, the objects in space and time are the clue to the discovery of, on the contrary, the noumena.