I m developing an application in rails. I have created a table say "student" in mysql. Is there anyway to create its migration file in rails application? I have specified databse name in config/database.yml" and using others table too. But i want to create tables migration file. How can i do it?
1 Answer
- Start by referencing your existing MySQL database in database.yml
- run
rake db:schema:dumpto generate the schema.rb file - Paste the
create_tablemethods from your schema.rb into a new migration, and Voila!
3 Comments
Michael Giovanni Pumo
I get this message: 'rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR'. What does it mean? I created a schema.rb file and rand the rake command again, but the same message appears. UPDATE: It seems that after getting that message, you need to run $rake db:schema:load
zakelfassi
@MichaelGiovanniPumo did you try without having the
schema.rb file ? (rename it and try again). Also, can you run rake commands ?Zoltán
@MichaelGiovanniPumo you're supposed to run
rake db:schema:dump (without the -T flag. -T is used to tell you what a particular command does, that's why you're getting that output :) I corrected it in the answer.