title: Laravel 5 - Add column and foreign key to an existing table with data
body: <p>I am very new at Laravel! But I'm trying. Here is were I could use some help;</p>
  
  <p>I have a posts table. I have a user table. But I forgot to add a foreign key in the posts table that links to the user id.</p>
  
  <p>The create users table migration:</p>
  
  <pre><code>use Illuminate\Support\Facades\Schema;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateUsersTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('users', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('name');
              $table-&gt;string('email')-&gt;unique();
              $table-&gt;string('password');
              $table-&gt;rememberToken();
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('users');
      }
  }
  </code></pre>
  
  <p>The create posts table migration:</p>
  
  <pre><code>use Illuminate\Support\Facades\Schema;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreatePostsTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('posts', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('title');
              $table-&gt;text('body');
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('posts');
      }
  }
  </code></pre>
  
  <p>I have created the new migration file:</p>
  
  <pre><code>use Illuminate\Support\Facades\Schema;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class AlterTablePostsAddForeignUser extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
        Schema::table('posts', function (Blueprint $table) {
            // I HAVE NO IDEA WHAT TO DO NEXT
        });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          //
      }
  }
  </code></pre>
  
  <p>I have no idea how to fill up the "public function up()" method here! If anyone can help! It will be much appreciated!</p>