title: How to write a migration for a rails model that belongs_to itself
body: <p>model scenario:</p>
  
  <pre><code>A node can belong to a parent node and can have child nodes.
  </code></pre>
  
  <p>models/node.rb </p>
  
  <pre><code>class Node &lt; ActiveRecord::Base                                                                
  
    has_many :children, class_name: "Node", foreign_key: "parent_id"                             
    belongs_to :parent, class_name: "Node"                                                       
  
  end           
  </code></pre>
  
  <p>db/migrations/20131031144907_create_nodes.rb</p>
  
  <pre><code>class CreateNodes &lt; ActiveRecord::Migration
    def change
      create_table :nodes do |t|
        t.timestamps
      end
    end
  end   
  </code></pre>
  
  <p>And then I want to do I migration to add the relations:</p>
  
  <pre><code>class AddNodesToNodes &lt; ActiveRecord::Migration
    def change
      add_column :nodes, :parent_id, :integer
      # how do i add childen?
    end
  end
  </code></pre>
  
  <p><strong>How do i add the has_many relationship in the migratation?</strong>                                                                        </p>