title: Unknown attribute error for parent id, only happening in test
body: <p>I have TopicList (parent) and Topic (child) models</p>
  
  <pre><code>class TopicList &lt; ApplicationRecord
      has_many :topics
      validates :name, presence: true , uniqueness: { case_sensitive: false }
  end
  
  class Topic &lt; ApplicationRecord
    belongs_to :topic_list
    validates :topic_list_id, presence: true
    validates :name, presence: true, uniqueness: { case_sensitive: false }
  end
  </code></pre>
  
  <p>The schema.rb includes:</p>
  
  <pre><code>ActiveRecord::Schema.define(version: 20161116031922) do
  
    create_table "topic_lists", force: :cascade do |t|
      t.string   "name"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.index ["name"], name: "index_topic_lists_on_name", unique: true
    end
  
    create_table "topics", force: :cascade do |t|
      t.string   "name"
      t.string   "source"
      t.integer  "position"
      t.integer  "topic_list_id"
      t.datetime "created_at",    null: false
      t.datetime "updated_at",    null: false
      t.index ["name"], name: "index_topics_on_name", unique: true
      t.index ["position"], name: "index_topics_on_position"
      t.index ["topic_list_id"], name: "index_topics_on_topic_list_id"
    end
  </code></pre>
  
  <p>My topic_test.rb starts by creating a new TopicList and building a Topic under it:</p>
  
  <pre><code>require 'test_helper'
  
  class TopicTest &lt; ActiveSupport::TestCase
    def setup
      @topic_list = TopicList.new(name: "Vocab")
      @topic_list.save
      @topic = @topic_list.topics.build(name: "Topic 1")
    end
  
    test "should be valid" do
      assert @topic.valid?
    end
  end
  </code></pre>
  
  <p>Whenever I run this test, I get the error:</p>
  
  <pre><code>ActiveModel::UnknownAttributeError: unknown attribute 'topic_list_id' for Topic.
  </code></pre>
  
  <p>But when I try the same sequence in my rails console, it works just fine.</p>
  
  <pre><code>Loading development environment (Rails 5.0.0.1)
  &gt;&gt; list = TopicList.new(name: "List 1")
  =&gt; #&lt;TopicList id: nil, name: "List 1", created_at: nil, updated_at: nil&gt;
  &gt;&gt; list.save
     (0.1ms)  begin transaction
    TopicList Exists (0.3ms)  SELECT  1 AS one FROM "topic_lists" WHERE LOWER("topic_lists"."name") = LOWER(?) LIMIT ?  [["name", "List 1"], ["LIMIT", 1]]
    SQL (0.3ms)  INSERT INTO "topic_lists" ("name", "created_at", "updated_at") VALUES (?, ?, ?)  [["name", "List 1"], ["created_at", 2016-11-16 21:23:33 UTC], ["updated_at", 2016-11-16 21:23:33 UTC]]
     (11.3ms)  commit transaction
  =&gt; true
  &gt;&gt; topic = list.topics.build(name: "Topic #1")
  =&gt; #&lt;Topic id: nil, name: "Topic #1", source: nil, position: nil, topic_list_id: 3, created_at: nil, updated_at: nil&gt;
  &gt;&gt; topic.valid?
    Topic Exists (0.2ms)  SELECT  1 AS one FROM "topics" WHERE LOWER("topics"."name") = LOWER(?) LIMIT ?  [["name", "Topic #1"], ["LIMIT", 1]]
  =&gt; true
  &gt;&gt; 
  </code></pre>
  
  <p>Every similar question I've found here deals with incorrect CamelCase, snake_case, or plural/single names. I think I've done all that correctly here. What am I missing?</p>