Lost my schema.rb! Can it be regenerated?

brad picture brad · Mar 16, 2012 · Viewed 53.3k times · Source

Due to some deployment issues I stopped tracking schema.rb in git. Somehow I have stuffed this up and somewhere along the way my schema.rb file has disappeared.

Is there a way of regenerating schema.rb from the database or from the migrations? I would prefer not to lose the existing data.

Answer

mguymon picture mguymon · Mar 16, 2012

If you run a rake -T it will list all possible rake tasks for your Rails project. One of them is db:schema:dump which will recreate the schema.rb for the Rails app from the database.

bundle exec rake db:schema:dump