title: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
body: <p>This seems to be a common problem but I can't find an answer that relates directly to this.</p>
  
  <p>I've got a users and designs tables and I'm trying to add a foreign key to the designs table to make it refer to the id on the users table.</p>
  
  <p>The migration for the users table:</p>
  
  <pre><code>    Schema::create('users', function(Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('username');
          $table-&gt;string('email')-&gt;unique();
          $table-&gt;string('password');
          $table-&gt;timestamps();
      });
  </code></pre>
  
  <p>The migration for the designs table:</p>
  
  <pre><code>    Schema::create('designs', function(Blueprint $table)
      {
          $table-&gt;engine = 'InnoDB';
  
          $table-&gt;increments('id')-&gt;unsigned();
          $table-&gt;string('title');
          $table-&gt;timestamps();
      });
  </code></pre>
  
  <p>The migration that I'm trying to do to add the foreign key:</p>
  
  <pre><code>public function up()
  {
      Schema::table('designs', function(Blueprint $table) {
          $table-&gt;integer('user_id')-&gt;unsigned();
          $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');
      });
  }
  
  
  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
      Schema::table('designs', function(Blueprint $table) {
          $table-&gt;dropColumn('user_id');
      });
  }
  </code></pre>
  
  <p>But I get the error message:</p>
  
  <pre><code>[Illuminate\Database\QueryException]
  SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`bootstrap`.`#sql-512_179`
  , CONSTRAINT `designs_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)) (SQL: alter table `designs` add constraint designs_user_
  id_foreign foreign key (`user_id`) references `users` (`id`))
  </code></pre>
  
  <p>What am I doing wrong here?</p>