title: Cannot add or update a child row: a foreign key constraint fails - Ruby on Rails
body: <p>My "child" form contains the following select:</p>
  
  <pre><code>&lt;%= child.select :parent_id, options_for_select(Parent.all.map{ |parent| parent.grandparent.name + " - " + parent.name }, {:include_blank =&gt; true}) %&gt;
  </code></pre>
  
  <p>On the "update" action, I get the following error:</p>
  
  <pre><code>Cannot add or update a child row: a foreign key constraint fails (`database_name`.`childs`, CONSTRAINT `fk_part2_5` FOREIGN KEY (`parent_id`) REFERENCES `parents` (`id`))
  </code></pre>
  
  <p>Models look like so:</p>
  
  <pre><code>class Child &lt; ApplicationRecord
    belongs_to :parent
  end
  
  class Parent &lt; ApplicationRecord
    has_many :childs, :dependent =&gt; :delete_all 
  end
  
  class GrandParent &lt; ApplicationRecord
    has_many :parents, :dependent =&gt; :delete_all
  end
  </code></pre>