title: ActiveRecord::UnknownAttributeError: unknown attribute 'user_id' for Post
body: <p>I am running into the following error when running my tests. The condition for the test to pass is that the user must be logged in to create posts. similar errors seem to mostly do with foreign_key but I seem to have it. Any help will be much appreciated. thanks!</p>
  
  <pre><code>Failure/Error: @post = current_user.posts.build(post_params)
  
   ActiveRecord::UnknownAttributeError:
     unknown attribute 'user_id' for Post.
  
  NoMethodError:
   #   undefined method `user_id=' for #&lt;Post:0x007fe1d0bf19e0&gt;
   #   Did you mean?  user=
   #   ./app/controllers/posts_controller.rb:10:in `create'
  </code></pre>
  
  <p><strong>post.rb</strong></p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    belongs_to :user
  end
  </code></pre>
  
  <p><strong>user.rb</strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :posts, dependent: :destroy
  end
  </code></pre>
  
  <p><strong>posts_controller.rb</strong></p>
  
  <pre><code>def create
    @post = current_user.posts.new(post_params)
    ...
  end
  </code></pre>
  
  <p><strong>schema.rb</strong></p>
  
  <pre><code>create_table "posts", force: :cascade do |t|
    t.string   "title"
    t.text     "body"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.integer  "user_id"
  end
  
  add_index "posts", ["user_id"], name: "index_posts_on_user_id"
  </code></pre>
  
  <p><strong>rspec test</strong></p>
  
  <pre><code>require "rails_helper"
  
  RSpec.describe "Creating post" do 
    let(:user) { User.create(username: "user", email: "mail@mail.com", 
    password: "password", password_confirmation: "password")}
  
    scenario "successfully" do 
      sign_in user
      visit root_path
      click_on "New Post"
  
      fill_in "Title", with: "title"
      fill_in "Body", with: "body"
      click_on "Submit"
  
      within (".content") do
        expect(page).to have_content("title")
        expect(page).to have_content("user")
      end
    end
  
    scenario "unsuccessfully" do 
      sign_in user
      visit root_path
      click_on "New Post"
  
      fill_in "Title", with: "Second Post"
      fill_in "Body", with: ""
      click_on "Submit"
  
      expect(page).to have_css ".error"
    end
  
    scenario "User not logged in cannot create posts" do 
      visit root_path
      click_on "New Post"
  
      expect(current_path).to eq(new_user_session_path)
    end
  end
  </code></pre>