title: Rails Generating Migrations From Model
body: <p>I've been reading about <a href="http://guides.rubyonrails.org/migrations.html" rel="nofollow">Rails Migrations</a> to help me start building a rails project.</p>
  
  <p>I'm a bit confused on the generation of the files in db/migrate.</p>
  
  <p>The way I've been designing my application is by starting with the models... outlining all of the objects that I'm going to have in the system as best I can. I would like to generate the migration files FROM these models automatically with the rails migration generator.</p>
  
  <p>Yes, I know "creating migrations manually is easy." And I know I could do it manually, but what I don't understand is why the tool is separated from the pre-created models.</p>
  
  <p>Based on my understanding from the article and other migration questions on SO, I can generate a migration like so:</p>
  
  <pre><code>rails generate migration SomeObj field:string some_other_field:integer
  </code></pre>
  
  <p>What I don't get is why I need to pass in the fields when my model already exists for SomeObj? Couldn't Rails detect it from the some_obj.rb and create the migration from there?</p>
  
  <p>Also, when I have a more complex model, with has_many, belongs_to, and has_to_and_belongs_to_many relationships, it would be really nice if it autocreated the JOIN tables and fields with the correct names (e.g. foreign_obj_id, foreign_obj_ids)</p>
  
  <p>In a previous project I didn't have to deal with migrations because I used Mongo+Mongoid - and collections were automatically generated due to the nature of how Mongo works (collections that doesn't exist get automatically created upon inserting or updating). Now with this Rails app I'm using Postgres (but I'm sure the same thing would happen with MySQL or any other relational database).</p>
  
  <p>Anyway, is there no helper for this kind of thing? Do I have to create all these migrations manually?</p>