11

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
  • I have specified databse name in config/development.rb ????? Commented Apr 23, 2013 at 11:14

1 Answer 1

37
  • Start by referencing your existing MySQL database in database.yml
  • run rake db:schema:dump to generate the schema.rb file
  • Paste the create_table methods from your schema.rb into a new migration, and Voila!
Sign up to request clarification or add additional context in comments.

3 Comments

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
@MichaelGiovanniPumo did you try without having the schema.rb file ? (rename it and try again). Also, can you run rake commands ?
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.