title: Ruby on Rails 5 setting has_one child to nil fails in console
body: <p>I'm currently working through the Ruby on Rails Essentials 5 training course on Lynda, and in the section on one-to-one associations, I create a "Subject" that has_one "Page." Each model looks like the following:</p>
  
  <pre><code>class Subject &lt; ApplicationRecord
  
      has_one :page
  
      scope :visible, lambda {where(:visible =&gt; true)}
      scope :invisible, lambda {where(:visible =&gt; false)}
      scope :sorted, lambda {order("position ASC")}
      scope :newest_first, lambda {order("created_at DESC")}
      scope :search, lambda {|query| where(["name LIKE ?", "%#{query}%"])}
  
  end
  </code></pre>
  
  <p>/////</p>
  
  <pre><code>class Page &lt; ApplicationRecord
  
      belongs_to :subject
  
  end
  </code></pre>
  
  <p>In the db, I have an existing Subject that I find by id and save to a variable. Then I create a new Page object (but not save it), and finally, I persist it by doing subject.page = page. The issue is, when I try to remove the association using subject.page = nil, I end up with the following error:</p>
  
  <pre><code>irb(main):004:0&gt; subject.page = nil
     (0.3ms)  BEGIN
     (0.2ms)  ROLLBACK
  ActiveRecord::RecordNotSaved: Failed to remove the existing associated 
  page. The record failed to save after its foreign key was set to nil.
      from (irb):4
  </code></pre>
  
  <p>I believe the expected behavior is for the page record to have its foreign key reassigned to NULL. This behavior is reflected in the tutorial I'm using, and in other posts about the subject. What am I missing here?</p>