title: Integrity constraint violation: 1452 laravel
body: <p>I have two tables in laravel created with the following migrations:</p>
  
  <p>User migration:</p>
  
  <pre><code>public function up()
  {
      Schema::create('users', function($table){
          $table-&gt;increments('id')-&gt;unsigned();
          $table-&gt;string('email')-&gt;unique();
          $table-&gt;string('password', 64);
          $table-&gt;string('first_name', 32);
          $table-&gt;string('last_name', 32);
          $table-&gt;string('remember_token', 100)-&gt;nullable();
      });
  }
  </code></pre>
  
  <p>Occasion migration:</p>
  
  <pre><code>public function up()
  {
      Schema::create('occasions', function($table){
          $table-&gt;increments('id')-&gt;unsigned();
          $table-&gt;integer('created_by_user_id')-&gt;unsigned();
          $table-&gt;foreign('created_by_user_id')-&gt;references('id')-&gt;on('users');
          $table-&gt;integer('updated_by_user_id')-&gt;unsigned();
          $table-&gt;foreign('updated_by_user_id')-&gt;references('id')-&gt;on('users');
          $table-&gt;timestamps();
          $table-&gt;string('title')-&gt;unique();
          $table-&gt;string('slug')-&gt;unique();
          $table-&gt;integer('category')-&gt;unsigned();
          $table-&gt;foreign('category')-&gt;references('id')-&gt;on('occasion_categories');
          $table-&gt;string('brand', 32);
          $table-&gt;string('model', 32)-&gt;nullable();
          $table-&gt;string('type', 32)-&gt;nullable();
          $table-&gt;string('body', 32)-&gt;nullable();
          $table-&gt;string('color', 32);
          $table-&gt;integer('fuel')-&gt;unsigned()-&gt;nullable();
          $table-&gt;foreign('fuel')-&gt;references('id')-&gt;on('occasion_fuels');
          $table-&gt;integer('transmission')-&gt;unsigned()-&gt;nullable();
          $table-&gt;foreign('transmission')-&gt;references('id')-&gt;on('occasion_transmissions');
          $table-&gt;decimal('usage', 6, 2)-&gt;nullable();
          $table-&gt;integer('engine_capacity')-&gt;unsigned()-&gt;nullable();
          $table-&gt;integer('building_year')-&gt;unsigned()-&gt;nullable();
          $table-&gt;string('sign', 8)-&gt;nullable();
          $table-&gt;date('mot')-&gt;nullable();
          $table-&gt;integer('kilometers')-&gt;nullable();
          $table-&gt;decimal('price', 8, 2);
          $table-&gt;decimal('action_price', 8, 2)-&gt;nullable();
          $table-&gt;text('description')-&gt;nullable();
      });
  }
  </code></pre>
  
  <p>Now when I try to create a Occasion with the following code:</p>
  
  <pre><code>Occasion::create(array(
      'created_by_user_id'=&gt;Auth::id(),
      'updated_by_user_id'=&gt;Auth::id(),
      'title'=&gt;Input::get('title'),
      'slug'=&gt;Str::slug(Input::get('title')),
      'category'=&gt;Input::get('category'),
      'brand'=&gt;Input::get('brand'),
      'model'=&gt;Input::get('model'),
      'type'=&gt;Input::get('type'),
      'body'=&gt;Input::get('body'),
      'color'=&gt;Input::get('color'),
      'fuel'=&gt;Input::get('fuel'),
      'transmission'=&gt;Input::get('transmission'),
      'usage'=&gt;Input::get('usage'),
      'engine_capacity'=&gt;Input::get('engine-capacity'),
      'building_year'=&gt;Input::get('building-year'),
      'sign'=&gt;Input::get('sign'),
      'mot'=&gt;Input::get('mot'),
      'kilometers'=&gt;Input::get('kilometers'),
      'price'=&gt;Input::get('price'),
      'action_price'=&gt;Input::get('action-price'),
      'description'=&gt;Input::get('description')
  ));
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (<code>henw</code>.<code>occasions</code>, CONSTRAINT <code>occasions_created_by_user_id_foreign</code> FOREIGN KEY (<code>created_by_user_id</code>) REFERENCES <code>users</code> (<code>id</code>)) (SQL: insert into <code>occasions</code> (<code>updated_at</code>, <code>created_at</code>) values (2014-06-30 18:42:11, 2014-06-30 18:42:11))</p>
  </blockquote>
  
  <p>I searched on Google but most of the people say I get this error because the foreign key does not exists, but that isn't true, because when i try to add the same values in PhpMyAdmin it does work and the user id which i am inserting is 1 and it does exist.</p>