Generating Schema from Existing Database

by Brian on 12/24/2007

If you’re porting an existing application to Rails, or building an application in Rails where the database schema already exists, here is a useful command to know:

rake db:schema:dump

This command will create a schema.rb in the db directory which you can then use to build your first migration. For example, copy the contents schema.rb into the file below:

class CreateMigration < ActiveRecord::Migration
def self.up
# Insert schema.rb here
end

def self.down
# I would say it's better not to define this, don't want to accidentally delete your existing data
end
end

Related posts:

  1. Filter Sensitive Data From Your Logs
  2. An Error Caused By Not Missing a Constant
  3. Booting from a CD in Mac OS X when ‘C’ doesn’t work
  4. NoMachine Mac OS X 10.6.3 bug
  5. Sudoku Application Update

Previous post:

Next post: