title: ActiveModel::UnknownAttributeError: unknown attribute when seeding belongs_to relationship
body: <p>Trying to seed a has_many/belongs_to relationship.
  A user has_many scripts, a script belongs_to a user.</p>
  
  <p>When seeding the script, I get this error:</p>
  
  <blockquote>
    <p>ActiveModel::UnknownAttributeError: unknown attribute 'user_id' for
    Script.</p>
  </blockquote>
  
  <p>I'd think that this line in my migration would create a user_id attribute for script?</p>
  
  <pre><code>t.belongs_to :user, index: true, foreign_key: true
  </code></pre>
  
  <p><em>app/models/script.rb</em></p>
  
  <pre><code>class Script &lt; ApplicationRecord
    belongs_to :user
    has_many :commits
    has_many :script_users, through: :commits, source: :user
  end
  </code></pre>
  
  <p><em>app/models/user.rb</em></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :scripts
    has_many :used_scripts, through: :commits, source: :script
    has_many :commits
  end
  </code></pre>
  
  <p><em>db/migrate/20171231022826_create_scripts.rb</em></p>
  
  <pre><code>class CreateScripts &lt; ActiveRecord::Migration[5.1]
    def change
      create_table :scripts do |t|
        t.string :name
        t.string :skill
        t.string :bot_for
        t.string :game_for
  
        t.belongs_to :user, index: true, foreign_key: true
  
        t.timestamps
      end
    end
  end
  </code></pre>
  
  <p><em>db/seeds.rb</em></p>
  
  <pre><code>admin = User.create!(
    email: 'a@a.com',
    password: 'adminadmin',
    password_confirmation: 'adminadmin'
  )
  
  script = Script.create!(
    name: 'YWoodcutter',
    skill: 'Woodcutting',
    bot_for: 'Android',
    game_for: "CandyLand,
    user_id: admin.id
  )
  </code></pre>
  
  <blockquote>
    <p>ActiveModel::UnknownAttributeError: unknown attribute 'user_id' for
    Script.
    I've made sure to rake:db reset and still get error.</p>
  </blockquote>
  
  <p>Thank you</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I did a few things and it's working OK now. I believe the issue may have been that my user migration was created after my script migration. The user migration should done before scripts, so I changed the dates to change the order they were migrated in. Did a rake rake db:rollback &amp; db:reset for good measure too.</p>