title: Rails - Not being able to create an instance even after adding foreign key
body: <p>I am creating the following tables in Rails (with Postgresql):</p>
  <ul>
  <li><code>User</code>: a user can be in one or more groups and can be the owner of one or more groups</li>
  <li><code>Group</code>: a group has an admin (which is one of the users) and one or more users</li>
  <li><code>Participant</code>: a participant the table in between the other two to connect them</li>
  </ul>
  <p>The models are like this:</p>
  <pre><code>#User.rb
  
  class User &lt; ApplicationRecord
    has_many :groups
    has_many :participants
  end
  </code></pre>
  <pre><code>#Group.rb
  
  class Group &lt; ApplicationRecord
    belongs_to :user
    has_many :participants
  end
  </code></pre>
  <pre><code>#Participant.rb
  
  class Participant &lt; ApplicationRecord
    belongs_to :group
    belongs_to :user
  end
  </code></pre>
  <p>After this, I did some migration to change the name of the <code>user_id</code> that the <code>Group</code> would have, into <code>admin_id</code>:</p>
  <pre><code>class ChangeForeignKeyForGroups &lt; ActiveRecord::Migration[6.1]
    def change
      rename_column :groups, :user_id, :admin_id
    end
  end
  </code></pre>
  <p>So now, my <code>schema</code> looks like this:</p>
  <pre><code>  create_table &quot;groups&quot;, force: :cascade do |t|
      t.string &quot;name&quot;
      t.text &quot;description&quot;
      t.integer &quot;participants&quot;
      t.bigint &quot;admin_id&quot;, null: false
      t.datetime &quot;created_at&quot;, precision: 6, null: false
      t.datetime &quot;updated_at&quot;, precision: 6, null: false
      t.index [&quot;admin_id&quot;], name: &quot;index_groups_on_admin_id&quot;
    end
  
    create_table &quot;participants&quot;, force: :cascade do |t|
      t.bigint &quot;group_id&quot;, null: false
      t.bigint &quot;user_id&quot;, null: false
      t.datetime &quot;created_at&quot;, precision: 6, null: false
      t.datetime &quot;updated_at&quot;, precision: 6, null: false
      t.index [&quot;group_id&quot;], name: &quot;index_participants_on_group_id&quot;
      t.index [&quot;user_id&quot;], name: &quot;index_participants_on_user_id&quot;
    end
  
    create_table &quot;users&quot;, force: :cascade do |t|
      t.string &quot;email&quot;, default: &quot;&quot;, null: false
      t.string &quot;encrypted_password&quot;, default: &quot;&quot;, null: false
      t.string &quot;reset_password_token&quot;
      t.datetime &quot;reset_password_sent_at&quot;
      t.datetime &quot;remember_created_at&quot;
      t.datetime &quot;created_at&quot;, precision: 6, null: false
      t.datetime &quot;updated_at&quot;, precision: 6, null: false
      t.string &quot;username&quot;
      t.index [&quot;email&quot;], name: &quot;index_users_on_email&quot;, unique: true
      t.index [&quot;reset_password_token&quot;], name: &quot;index_users_on_reset_password_token&quot;, unique: true
  </code></pre>
  <p>The problem is that once I try to create a Group in seeds, I keep having this error:</p>
  <pre><code>pry(main)&gt; group = Group.new(name: &quot;Test Group&quot;, description: &quot;blablabal&quot;)
  =&gt; #&lt;Group:0x00007fdbcdd03f80 id: nil, name: &quot;Test Group&quot;, description: &quot;blablabal&quot;, participants: nil, admin_id: nil, created_at: nil, updated_at: nil&gt;
  [5] pry(main)&gt; group.valid?
  =&gt; false
  [6] pry(main)&gt; group.errors
  =&gt; #&lt;ActiveModel::Errors:0x00007fdbcdc7ad98
   @base=#&lt;Group:0x00007fdbcdd03f80 id: nil, name: &quot;Test Group&quot;, description: &quot;blablabal&quot;, participants: nil, admin_id: nil, created_at: nil, updated_at: nil&gt;,
   @errors=[#&lt;ActiveModel::Error attribute=user, type=blank, options={:message=&gt;:required}&gt;]&gt;
  </code></pre>
  <p>It seems I am missing the <code>user</code>, so I try adding it but it throws the same error:</p>
  <pre><code>user = User.first
    User Load (1.4ms)  SELECT &quot;users&quot;.* FROM &quot;users&quot; ORDER BY &quot;users&quot;.&quot;id&quot; ASC LIMIT $1  [[&quot;LIMIT&quot;, 1]]
  =&gt; #&lt;User id: 7, email: &quot;jose@test.io&quot;, created_at: &quot;2022-05-31 10:29:06.208673000 +0000&quot;, updated_at: &quot;2022-05-31 10:29:06.208673000 +0000&quot;, username: &quot;Jose&quot;&gt;
  
  pry(main)&gt; group = Group.new(name: &quot;Test Group&quot;, description: &quot;blablabal&quot;, admin_id: user.id)
  =&gt; #&lt;Group:0x00007fdbdd205ad8 id: nil, name: &quot;Test Group&quot;, description: &quot;blablabal&quot;, participants: nil, admin_id: 7, created_at: nil, updated_at: nil&gt;
  [13] pry(main)&gt; group.valid?
  =&gt; false
  [14] pry(main)&gt; group.errors
  =&gt; #&lt;ActiveModel::Errors:0x00007fdbdd1d4578
   @base=#&lt;Group:0x00007fdbdd205ad8 id: nil, name: &quot;Test Group&quot;, description: &quot;blablabal&quot;, participants: nil, admin_id: 7, created_at: nil, updated_at: nil&gt;,
   @errors=[#&lt;ActiveModel::Error attribute=user, type=blank, options={:message=&gt;:required}&gt;]&gt;
  </code></pre>
  <p>Am I doing something wrong? Have I structure it wrongly? Thanks!</p>